-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccms.go
More file actions
115 lines (95 loc) · 2.34 KB
/
ccms.go
File metadata and controls
115 lines (95 loc) · 2.34 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
"os"
"path/filepath"
"flag"
"github.com/CCDirectLink/ccms/cmd/cmd"
"github.com/CCDirectLink/ccms/cmd/help"
"github.com/CCDirectLink/ccms/internal/logger"
"github.com/CCDirectLink/ccms/internal/utils"
)
func main() {
dir, err := os.Getwd()
workdir := flag.String("wd", dir, "a string")
logLevel := flag.Int("log-level", logger.AllLevel, "set log level. default=15")
flag.Parse()
if flag.NArg() < 1 {
help.Default()
return
}
logger.SetLogLevel(*logLevel)
wd := *workdir
if err != nil {
panic(err)
}
op := flag.Arg(0)
basePackage, err := utils.GetPackage(filepath.Join(wd, "package.json"))
hasPackage := true
if err != nil {
basePackage = utils.InitPackage()
hasPackage = false
}
switch op {
case "new", "n":
wd = cmd.New(wd, basePackage)
if wd != "" {
utils.SavePackage(wd, basePackage)
utils.MakeScripts(wd, basePackage)
}
case "init", "in":
cmd.Init(basePackage)
utils.SavePackage(wd, basePackage)
utils.MakeScripts(wd, basePackage)
case "install", "i":
if !hasPackage {
logger.Critical("main", "could not find package.json in current directory")
return
}
names := make([]string, 0)
if flag.NArg() > 1 {
logger.Info("install", "using cmd args to install")
names = flag.Args()[1:]
} else {
logger.Info("install", "using package mod dep keys to install")
for key := range basePackage.ModDep {
names = append(names, key)
}
}
for _, name := range names {
stats := []*cmd.InstallStats{}
stat := cmd.Install(wd, name, stats)
if stat != nil {
if stat.Err != "" {
panic(stat.Err)
}
}
if stat.Entry != nil {
entry := stat.Entry
basePackage.ModDep[entry.Name] = entry.Version
}
}
utils.SavePackage(wd, basePackage)
case "uninstall", "ui":
if !hasPackage {
logger.Critical("main", "could not find package.json in current directory")
return
}
names := make([]string, 0)
if flag.NArg() > 1 {
logger.Info("uninstall", "using cmd args to uninstall")
names = flag.Args()[1:]
} else {
logger.Info("uninstall", "using package mod dep keys to uninstall")
for key := range basePackage.ModDep {
names = append(names, key)
}
}
for _, name := range names {
cmd.Uninstall(wd, name, basePackage)
}
utils.SavePackage(wd, basePackage)
default:
fmt.Printf("Invalid command: %s", op)
}
}