-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
103 lines (101 loc) · 2.08 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"go/build"
"os"
)
// main parses arguments and flags and passes the arguments to the correct
// handler function.
func main() {
var err error
if len(os.Args) < 2 {
printErr("Subcommand not specified")
flagMap["main"].Usage()
os.Exit(1)
} else {
var cwd string
if cwd, err = os.Getwd(); err != nil {
printErr("Error : " + err.Error())
os.Exit(1)
}
ctx := &build.Default
ctx.UseAllFiles = true
switch os.Args[1] {
case "list":
f := flagMap["list"]
f.Parse(os.Args[2:])
var path string
if len(f.Args()) > 0 {
path = f.Arg(0)
} else {
path = "."
}
err = list(ctx, cwd, path)
case "info":
f := flagMap["info"]
f.Parse(os.Args[2:])
var path string
if len(f.Args()) > 0 {
path = f.Arg(0)
} else {
path = "."
}
err = info(ctx, cwd, path)
case "init":
f := flagMap["init"]
f.Parse(os.Args[2:])
if len(f.Args()) > 0 {
err = initc(ctx, cwd, f.Arg(0), opt.recurse, opt.hidden)
} else {
printErr("Missing argument")
f.Usage()
os.Exit(1)
}
case "cp":
f := flagMap["cp"]
f.Parse(os.Args[2:])
if len(f.Args()) > 1 {
err = cp(ctx, cwd, f.Arg(0), f.Arg(1), opt.recurse, opt.hidden)
} else {
printErr("Missing arguments")
f.Usage()
os.Exit(1)
}
case "mv":
f := flagMap["mv"]
f.Parse(os.Args[2:])
if len(f.Args()) > 1 {
err = mv(ctx, cwd, f.Arg(0), f.Arg(1), opt.recurse, opt.hidden)
if err == ErrStandardPackage {
printErr("Cannot move standard package")
f.Usage()
os.Exit(1)
}
} else {
printErr("Missing arguments")
f.Usage()
os.Exit(1)
}
case "path":
f := flagMap["path"]
f.Parse(os.Args[2:])
if len(f.Args()) > 1 {
err = path(ctx, cwd, f.Arg(0), f.Arg(1), opt.recurse)
} else {
printErr("Missing arguments")
f.Usage()
os.Exit(1)
}
case "-h":
flagMap["main"].Usage()
default:
printErr("Invalid subcommand : " + os.Args[1])
flagMap["main"].Usage()
os.Exit(1)
}
}
// Output errors and exit
if err != nil {
printErr("Error : " + err.Error())
os.Exit(1)
}
}