/
main.go
38 lines (35 loc) · 833 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
package main
import (
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"os"
)
func main() {
os.Exit(realMain(os.Args[1:], Commands()))
}
func realMain(args []string, commands map[string]cli.CommandFactory) int {
for _, arg := range args {
if arg == "-v" || arg == "-version" || arg == "--version" {
newArgs := make([]string, len(args)+1)
newArgs[0] = "version"
copy(newArgs[1:], args)
args = newArgs
break
}
}
cmdNames := make([]string, 0, len(commands))
for cmdName := range commands {
cmdNames = append(cmdNames, cmdName)
}
cli := &cli.CLI{
Args: args,
Commands: commands,
HelpFunc: cli.FilteredHelpFunc(cmdNames, cli.BasicHelpFunc("gypsy")),
}
exitCode, err := cli.Run()
if err != nil {
log.Warnf("Error executing CLI: %s", err.Error())
return 1
}
return exitCode
}