-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
82 lines (73 loc) · 1.45 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
package main
import (
"errors"
"flag"
"fmt"
"os"
"sqlpkg.org/cli/cmd/help"
"sqlpkg.org/cli/cmd/info"
init_ "sqlpkg.org/cli/cmd/init"
"sqlpkg.org/cli/cmd/install"
"sqlpkg.org/cli/cmd/list"
"sqlpkg.org/cli/cmd/uninstall"
"sqlpkg.org/cli/cmd/update"
"sqlpkg.org/cli/cmd/which"
"sqlpkg.org/cli/logx"
)
var version = "main"
func parseArgs() (command string, args []string) {
if len(os.Args) < 2 {
return "", nil
}
var isVerbose bool
if flag.Lookup("v") == nil {
flag.BoolVar(&isVerbose, "v", false, "verbose output")
}
flag.Parse()
logx.SetVerbose(isVerbose)
args = flag.Args()
command, args = args[0], args[1:]
return
}
func execCommand(command string, args []string) error {
if command == "" {
return help.Help(nil)
}
switch command {
case "init":
return init_.Init(args)
case "install":
if len(args) == 0 {
return install.InstallAll(args)
}
return install.Install(args)
case "uninstall":
return uninstall.Uninstall(args)
case "update":
if len(args) == 0 {
return update.UpdateAll(args)
}
return update.Update(args)
case "list":
return list.List(args)
case "info":
return info.Info(args)
case "which":
return which.Which(args)
case "help":
return help.Help(args)
case "version":
fmt.Println(version)
return nil
default:
return errors.New("unknown command")
}
}
func main() {
command, args := parseArgs()
err := execCommand(command, args)
if err != nil {
fmt.Println("!", err)
os.Exit(1)
}
}