github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/hashicorp/consul/lib"
     8  	"github.com/mitchellh/cli"
     9  )
    10  
    11  func init() {
    12  	lib.SeedMathRand()
    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 "fs ls", "fs cat", "fs stat":
    43  		case "check":
    44  		default:
    45  			commandsInclude = append(commandsInclude, k)
    46  		}
    47  	}
    48  
    49  	cli := &cli.CLI{
    50  		Args:     args,
    51  		Commands: commands,
    52  		HelpFunc: cli.FilteredHelpFunc(commandsInclude, cli.BasicHelpFunc("nomad")),
    53  	}
    54  
    55  	exitCode, err := cli.Run()
    56  	if err != nil {
    57  		fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
    58  		return 1
    59  	}
    60  
    61  	return exitCode
    62  }