Ejemplo n.º 1
0
func ExampleContext_RegisterCommand() {
	context := cmd.NewContext(
		"A tree where we can register commands",
		`This is the root of the command tree and is where
                 we put all commands and subgroups`)

	sampleCmd := &cmd.Command{
		Brief: "A command",
		Body: func(*cmd.Context, *cmd.Command, []string) error {
			return nil
		},
	}

	context.RegisterCommand([]string{"init"}, sampleCmd)
}
Ejemplo n.º 2
0
var flagRoot string
var flagLevel int

var brief = "Utility for managing a stable of MySQL servers"

var description = `Easy creation and distribution of MySQL
servers. The utility support running different versions of servers at
the same time.

To create a new stable, use 'init'.

To add a distribution, use 'distribution add'.

To get help on a command, use the 'help <command>'.`

var context *cmd.Context = cmd.NewContext(brief, description)

func main() {
	flag.Parse()

	if args := flag.Args(); len(args) == 0 {
		flag.Usage()
		os.Exit(2)
	} else {
		prog := filepath.Base(os.Args[0])
		context.RootDir = flagRoot
		log.SetPriority(log.Priority(flagLevel))

		if err := context.RunCommand(args); err != nil {
			fmt.Fprintf(os.Stderr, "%s: %s\n", prog, err)
			os.Exit(2)