-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (78 loc) · 1.84 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"embed"
"os"
"strconv"
"github.com/gookit/color"
"github.com/urfave/cli/v2"
"Component-Manager/command"
"Component-Manager/module"
)
//go:embed .cmrc.official.json
var configFile embed.FS
var GITHUB_TOKEN string
func main() {
os.Setenv("GITHUB_TOKEN", GITHUB_TOKEN)
officialConfigBytes, err := configFile.ReadFile(".cmrc.official.json")
if err != nil {
color.Redln(err)
os.Exit(1)
}
app := &cli.App{
Name: "Component-Manager",
HelpName: "cm",
Usage: "a tool for managing JS/TS components and modules.",
Version: "v1.5.7",
Commands: []*cli.Command{
{
Name: "version",
Aliases: []string{"v"},
Usage: "show the version of cm",
Action: command.Version,
},
{
Name: "init",
Usage: "initialize a new project",
Before: func(ctx *cli.Context) error {
upToDate, err := module.CheckRemoteVersion(ctx, true)
if err != nil {
return err
} else if !upToDate {
color.Normal.Println()
}
return module.LoadAppConfig(ctx, officialConfigBytes)
},
Action: command.Init,
},
{
Name: "add",
Aliases: []string{"a", "get", "download"},
Usage: "add a new component",
Before: func(ctx *cli.Context) error {
upToDate, err := module.CheckRemoteVersion(ctx, true)
if err != nil {
return err
} else if !upToDate {
color.Normal.Println()
}
return module.LoadAppConfig(ctx, officialConfigBytes)
},
Action: command.Add,
},
{
Name: "update",
Aliases: []string{"upgrade"},
Usage: "update the component manager",
Action: command.Update,
},
},
}
if err := app.Run(os.Args); err != nil {
var errorString = err.Error()
if errorNumber, err := strconv.Atoi(errorString); err == nil {
os.Exit(errorNumber)
}
color.Redln(errorString)
os.Exit(1)
}
}