github.com/dkerwin/nomad@v0.3.3-0.20160525181927-74554135514b/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  		case "fs ls", "fs cat", "fs stat":
    38  		case "check":
    39  		default:
    40  			commandsInclude = append(commandsInclude, k)
    41  		}
    42  	}
    43  
    44  	cli := &cli.CLI{
    45  		Args:     args,
    46  		Commands: commands,
    47  		HelpFunc: cli.FilteredHelpFunc(commandsInclude, cli.BasicHelpFunc("nomad")),
    48  	}
    49  
    50  	exitCode, err := cli.Run()
    51  	if err != nil {
    52  		fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
    53  		return 1
    54  	}
    55  
    56  	return exitCode
    57  }