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