func subCommandAction(command string, operand string, runner command_runner.Runner) func(context *cli.Context) { return func(context *cli.Context) { err := runner.RunSubCmdByName(command, operand, context) if err != nil { fmt.Fprintln(os.Stderr, err) } } }
func getCommand(baseName string, metadata command_metadata.CommandMetadata, runner command_runner.Runner) cli.Command { return cli.Command{ Name: metadata.Name, ShortName: metadata.ShortName, Description: metadata.Description, Usage: strings.Replace(metadata.Usage, "BROOKLYN_NAME", baseName, -1), Action: func(context *cli.Context) { err := runner.RunCmdByName(metadata.Name, context) if err != nil { fmt.Println(err) } }, Flags: metadata.Flags, SkipFlagParsing: metadata.SkipFlagParsing, } }
func getCommand(baseName string, metadata command_metadata.CommandMetadata, runner command_runner.Runner) cli.Command { command := cli.Command{ Name: metadata.Name, Aliases: metadata.Aliases, ShortName: metadata.ShortName, Description: metadata.Description, Usage: strings.Replace(metadata.Usage, "BROOKLYN_NAME", baseName, -1), Action: func(context *cli.Context) { err := runner.RunCmdByName(metadata.Name, context) if err != nil { error_handler.ErrorExit(err) } }, Flags: metadata.Flags, SkipFlagParsing: metadata.SkipFlagParsing, } if nil != metadata.Operands { command.Subcommands = make([]cli.Command, 0) for _, operand := range metadata.Operands { command.Subcommands = append(command.Subcommands, cli.Command{ Name: operand.Name, Aliases: operand.Aliases, ShortName: operand.ShortName, Description: operand.Description, Usage: operand.Usage, Flags: operand.Flags, SkipFlagParsing: operand.SkipFlagParsing, Action: subCommandAction(command.Name, operand.Name, runner), }) command.Usage = strings.Join([]string{ command.Usage, "\n... ", operand.Usage, "\t", operand.Description, }, "") } } return command }