-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (46 loc) · 868 Bytes
/
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
package main
import (
"fmt"
"os"
)
func main() {
if err := runMain(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
var scriptName string
var scriptArgs []string
func runMain() error {
displayHelp := false
Loop:
for idx, arg := range os.Args {
if idx == 0 {
continue
}
switch {
case arg == "__complete" || arg == "__completeNoDesc":
break Loop
case arg == "--help" || arg == "-h":
displayHelp = true
continue
case arg == "--completion":
shell := "unknown"
if len(os.Args) > idx+1 {
shell = os.Args[idx+1]
}
return completion(shell)
case arg[0] != '-':
scriptName = arg
scriptArgs = os.Args[idx+1:]
os.Args = os.Args[:idx+1]
break Loop
default:
return fmt.Errorf("unknown flag: %s", arg)
}
}
if displayHelp || len(os.Args) == 1 {
return runCmd.Help()
}
return runCmd.Execute()
}