github.com/ranjib/nomad@v0.1.1-0.20160225204057-97751b02f70b/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/mitchellh/cli" 8 ) 9 10 func main() { 11 os.Exit(Run(os.Args[1:])) 12 } 13 14 func Run(args []string) int { 15 return RunCustom(args, Commands(nil)) 16 } 17 18 func RunCustom(args []string, commands map[string]cli.CommandFactory) int { 19 // Get the command line args. We shortcut "--version" and "-v" to 20 // just show the version. 21 for _, arg := range args { 22 if arg == "-v" || arg == "-version" || arg == "--version" { 23 newArgs := make([]string, len(args)+1) 24 newArgs[0] = "version" 25 copy(newArgs[1:], args) 26 args = newArgs 27 break 28 } 29 } 30 31 // Build the commands to include in the help now. 32 commandsInclude := make([]string, 0, len(commands)) 33 for k, _ := range commands { 34 switch k { 35 case "executor": 36 case "syslog": 37 default: 38 commandsInclude = append(commandsInclude, k) 39 } 40 } 41 42 cli := &cli.CLI{ 43 Args: args, 44 Commands: commands, 45 HelpFunc: cli.FilteredHelpFunc(commandsInclude, cli.BasicHelpFunc("nomad")), 46 } 47 48 exitCode, err := cli.Run() 49 if err != nil { 50 fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error()) 51 return 1 52 } 53 54 return exitCode 55 }