From 7b9c17c127af7c81e19bc38edba4813dd0d5023d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20P=C3=A9rez?= Date: Wed, 7 Jun 2023 17:53:22 +0200 Subject: [PATCH] cli: remove AddHelpCategory and improve AddCommand * AddHelpCategory() was removed in favor of an exported HelpCategories global. * AddCommand() now accepts a CmdInfo struct as its sole argument. --- internals/cli/cli.go | 116 ++++++++++++++------------------- internals/cli/cmd_add.go | 8 ++- internals/cli/cmd_autostart.go | 8 ++- internals/cli/cmd_changes.go | 21 ++++-- internals/cli/cmd_checks.go | 8 ++- internals/cli/cmd_enter.go | 15 +++-- internals/cli/cmd_exec.go | 14 ++-- internals/cli/cmd_help.go | 28 ++++---- internals/cli/cmd_help_test.go | 2 +- internals/cli/cmd_logs.go | 8 ++- internals/cli/cmd_ls.go | 8 ++- internals/cli/cmd_mkdir.go | 8 ++- internals/cli/cmd_plan.go | 7 +- internals/cli/cmd_replan.go | 8 ++- internals/cli/cmd_restart.go | 8 ++- internals/cli/cmd_rm.go | 8 ++- internals/cli/cmd_run.go | 9 ++- internals/cli/cmd_services.go | 10 ++- internals/cli/cmd_signal.go | 7 +- internals/cli/cmd_start.go | 8 ++- internals/cli/cmd_stop.go | 8 ++- internals/cli/cmd_version.go | 8 ++- internals/cli/cmd_warnings.go | 21 ++++-- 23 files changed, 226 insertions(+), 120 deletions(-) diff --git a/internals/cli/cli.go b/internals/cli/cli.go index 75dcaacf..cd901ea7 100644 --- a/internals/cli/cli.go +++ b/internals/cli/cli.go @@ -63,52 +63,34 @@ var optionsData options // ErrExtraArgs is returned if extra arguments to a command are found var ErrExtraArgs = fmt.Errorf("too many arguments for command") -// cmdInfo holds information needed to call parser.AddCommand(...). -type cmdInfo struct { - name, shortHelp, longHelp string - builder func() flags.Commander - hidden bool - optDescs map[string]string - argDescs []argDesc - alias string - extra func(*flags.Command) +// CmdInfo holds information needed to call parser.AddCommand(...). +type CmdInfo struct { + Name, ShortHelp, LongHelp string + Builder func() flags.Commander + Hidden bool + OptDescs map[string]string + ArgDescs []argDesc + Alias string + Extra func(*flags.Command) } // commands holds information about all non-debug commands. -var commands []*cmdInfo +var commands []*CmdInfo // debugCommands holds information about all debug commands. -var debugCommands []*cmdInfo +var debugCommands []*CmdInfo // AddCommand replaces parser.addCommand() in a way that is compatible with // re-constructing a pristine parser. -func AddCommand(name, shortHelp, longHelp string, builder func() flags.Commander, optDescs map[string]string, argDescs []argDesc) *cmdInfo { - info := &cmdInfo{ - name: name, - shortHelp: shortHelp, - longHelp: longHelp, - builder: builder, - optDescs: optDescs, - argDescs: argDescs, - } +func AddCommand(info *CmdInfo) { commands = append(commands, info) - return info } // addDebugCommand replaces parser.addCommand() in a way that is // compatible with re-constructing a pristine parser. It is meant for // adding debug commands. -func addDebugCommand(name, shortHelp, longHelp string, builder func() flags.Commander, optDescs map[string]string, argDescs []argDesc) *cmdInfo { - info := &cmdInfo{ - name: name, - shortHelp: shortHelp, - longHelp: longHelp, - builder: builder, - optDescs: optDescs, - argDescs: argDescs, - } +func addDebugCommand(info *CmdInfo) { debugCommands = append(debugCommands, info) - return info } type parserSetter interface { @@ -192,7 +174,7 @@ func Parser(cli *client.Client) *flags.Parser { // Add all regular commands for _, c := range commands { - obj := c.builder() + obj := c.Builder() if x, ok := obj.(clientSetter); ok { x.setClient(cli) } @@ -200,51 +182,51 @@ func Parser(cli *client.Client) *flags.Parser { x.setParser(parser) } - cmd, err := parser.AddCommand(c.name, c.shortHelp, strings.TrimSpace(c.longHelp), obj) + cmd, err := parser.AddCommand(c.Name, c.ShortHelp, strings.TrimSpace(c.LongHelp), obj) if err != nil { - logger.Panicf("cannot add command %q: %v", c.name, err) + logger.Panicf("cannot add command %q: %v", c.Name, err) } - cmd.Hidden = c.hidden - if c.alias != "" { - cmd.Aliases = append(cmd.Aliases, c.alias) + cmd.Hidden = c.Hidden + if c.Alias != "" { + cmd.Aliases = append(cmd.Aliases, c.Alias) } opts := cmd.Options() - if c.optDescs != nil && len(opts) != len(c.optDescs) { - logger.Panicf("wrong number of option descriptions for %s: expected %d, got %d", c.name, len(opts), len(c.optDescs)) + if c.OptDescs != nil && len(opts) != len(c.OptDescs) { + logger.Panicf("wrong number of option descriptions for %s: expected %d, got %d", c.Name, len(opts), len(c.OptDescs)) } for _, opt := range opts { name := opt.LongName if name == "" { name = string(opt.ShortName) } - desc, ok := c.optDescs[name] - if !(c.optDescs == nil || ok) { - logger.Panicf("%s missing description for %s", c.name, name) + desc, ok := c.OptDescs[name] + if !(c.OptDescs == nil || ok) { + logger.Panicf("%s missing description for %s", c.Name, name) } - lintDesc(c.name, name, desc, opt.Description) + lintDesc(c.Name, name, desc, opt.Description) if desc != "" { opt.Description = desc } } args := cmd.Args() - if c.argDescs != nil && len(args) != len(c.argDescs) { - logger.Panicf("wrong number of argument descriptions for %s: expected %d, got %d", c.name, len(args), len(c.argDescs)) + if c.ArgDescs != nil && len(args) != len(c.ArgDescs) { + logger.Panicf("wrong number of argument descriptions for %s: expected %d, got %d", c.Name, len(args), len(c.ArgDescs)) } for i, arg := range args { name, desc := arg.Name, "" - if c.argDescs != nil { - name = c.argDescs[i].name - desc = c.argDescs[i].desc + if c.ArgDescs != nil { + name = c.ArgDescs[i].name + desc = c.ArgDescs[i].desc } - lintArg(c.name, name, desc, arg.Description) + lintArg(c.Name, name, desc, arg.Description) name = fixupArg(name) arg.Name = name arg.Description = desc } - if c.extra != nil { - c.extra(cmd) + if c.Extra != nil { + c.Extra(cmd) } } // Add the debug command @@ -255,45 +237,45 @@ func Parser(cli *client.Client) *flags.Parser { } // Add all the sub-commands of the debug command for _, c := range debugCommands { - obj := c.builder() + obj := c.Builder() if x, ok := obj.(clientSetter); ok { x.setClient(cli) } - cmd, err := debugCommand.AddCommand(c.name, c.shortHelp, strings.TrimSpace(c.longHelp), obj) + cmd, err := debugCommand.AddCommand(c.Name, c.ShortHelp, strings.TrimSpace(c.LongHelp), obj) if err != nil { - logger.Panicf("cannot add debug command %q: %v", c.name, err) + logger.Panicf("cannot add debug command %q: %v", c.Name, err) } - cmd.Hidden = c.hidden + cmd.Hidden = c.Hidden opts := cmd.Options() - if c.optDescs != nil && len(opts) != len(c.optDescs) { - logger.Panicf("wrong number of option descriptions for %s: expected %d, got %d", c.name, len(opts), len(c.optDescs)) + if c.OptDescs != nil && len(opts) != len(c.OptDescs) { + logger.Panicf("wrong number of option descriptions for %s: expected %d, got %d", c.Name, len(opts), len(c.OptDescs)) } for _, opt := range opts { name := opt.LongName if name == "" { name = string(opt.ShortName) } - desc, ok := c.optDescs[name] - if !(c.optDescs == nil || ok) { - logger.Panicf("%s missing description for %s", c.name, name) + desc, ok := c.OptDescs[name] + if !(c.OptDescs == nil || ok) { + logger.Panicf("%s missing description for %s", c.Name, name) } - lintDesc(c.name, name, desc, opt.Description) + lintDesc(c.Name, name, desc, opt.Description) if desc != "" { opt.Description = desc } } args := cmd.Args() - if c.argDescs != nil && len(args) != len(c.argDescs) { - logger.Panicf("wrong number of argument descriptions for %s: expected %d, got %d", c.name, len(args), len(c.argDescs)) + if c.ArgDescs != nil && len(args) != len(c.ArgDescs) { + logger.Panicf("wrong number of argument descriptions for %s: expected %d, got %d", c.Name, len(args), len(c.ArgDescs)) } for i, arg := range args { name, desc := arg.Name, "" - if c.argDescs != nil { - name = c.argDescs[i].name - desc = c.argDescs[i].desc + if c.ArgDescs != nil { + name = c.ArgDescs[i].name + desc = c.ArgDescs[i].desc } - lintArg(c.name, name, desc, arg.Description) + lintArg(c.Name, name, desc, arg.Description) name = fixupArg(name) arg.Name = name arg.Description = desc diff --git a/internals/cli/cmd_add.go b/internals/cli/cmd_add.go index e477e3b5..7734de1f 100644 --- a/internals/cli/cmd_add.go +++ b/internals/cli/cmd_add.go @@ -67,5 +67,11 @@ func (cmd *cmdAdd) Execute(args []string) error { } func init() { - AddCommand("add", shortAddHelp, longAddHelp, func() flags.Commander { return &cmdAdd{} }, addDescs, nil) + AddCommand(&CmdInfo{ + Name: "add", + ShortHelp: shortAddHelp, + LongHelp: longAddHelp, + Builder: func() flags.Commander { return &cmdAdd{} }, + OptDescs: addDescs, + }) } diff --git a/internals/cli/cmd_autostart.go b/internals/cli/cmd_autostart.go index 31f38f41..a8601aea 100644 --- a/internals/cli/cmd_autostart.go +++ b/internals/cli/cmd_autostart.go @@ -31,7 +31,13 @@ type cmdAutoStart struct { } func init() { - AddCommand("autostart", shortAutoStartHelp, longAutoStartHelp, func() flags.Commander { return &cmdAutoStart{} }, waitDescs, nil) + AddCommand(&CmdInfo{ + Name: "autostart", + ShortHelp: shortAutoStartHelp, + LongHelp: longAutoStartHelp, + Builder: func() flags.Commander { return &cmdAutoStart{} }, + OptDescs: waitDescs, + }) } func (cmd cmdAutoStart) Execute(args []string) error { diff --git a/internals/cli/cmd_changes.go b/internals/cli/cmd_changes.go index be238a3a..19b8bf34 100644 --- a/internals/cli/cmd_changes.go +++ b/internals/cli/cmd_changes.go @@ -48,12 +48,21 @@ type cmdTasks struct { } func init() { - AddCommand("changes", shortChangesHelp, longChangesHelp, - func() flags.Commander { return &cmdChanges{} }, timeDescs, nil) - AddCommand("tasks", shortTasksHelp, longTasksHelp, - func() flags.Commander { return &cmdTasks{} }, - merge(changeIDMixinOptDesc, timeDescs), - changeIDMixinArgDesc) + AddCommand(&CmdInfo{ + Name: "changes", + ShortHelp: shortChangesHelp, + LongHelp: longChangesHelp, + Builder: func() flags.Commander { return &cmdChanges{} }, + OptDescs: timeDescs, + }) + AddCommand(&CmdInfo{ + Name: "tasks", + ShortHelp: shortTasksHelp, + LongHelp: longTasksHelp, + Builder: func() flags.Commander { return &cmdTasks{} }, + OptDescs: merge(changeIDMixinOptDesc, timeDescs), + ArgDescs: changeIDMixinArgDesc, + }) } type changesByTime []*client.Change diff --git a/internals/cli/cmd_checks.go b/internals/cli/cmd_checks.go index 6fe93d34..92e8d5ed 100644 --- a/internals/cli/cmd_checks.go +++ b/internals/cli/cmd_checks.go @@ -79,5 +79,11 @@ func (cmd *cmdChecks) Execute(args []string) error { } func init() { - AddCommand("checks", shortChecksHelp, longChecksHelp, func() flags.Commander { return &cmdChecks{} }, checksDescs, nil) + AddCommand(&CmdInfo{ + Name: "checks", + ShortHelp: shortChecksHelp, + LongHelp: longChecksHelp, + Builder: func() flags.Commander { return &cmdChecks{} }, + OptDescs: checksDescs, + }) } diff --git a/internals/cli/cmd_enter.go b/internals/cli/cmd_enter.go index 0d93b3d8..0343e521 100644 --- a/internals/cli/cmd_enter.go +++ b/internals/cli/cmd_enter.go @@ -58,10 +58,17 @@ func init() { for k, v := range sharedRunEnterOptsHelp { optsHelp[k] = v } - cmdInfo := AddCommand("enter", shortEnterHelp, longEnterHelp, func() flags.Commander { return &cmdEnter{} }, optsHelp, nil) - cmdInfo.extra = func(cmd *flags.Command) { - cmd.PassAfterNonOption = true - } + AddCommand(&CmdInfo{ + Name: "enter", + ShortHelp: shortEnterHelp, + LongHelp: longEnterHelp, + Builder: func() flags.Commander { return &cmdEnter{} }, + OptDescs: optsHelp, + + Extra: func(cmd *flags.Command) { + cmd.PassAfterNonOption = true + }, + }) } func commandEnterFlags(commander flags.Commander) (enterFlags enterFlags, supported bool) { diff --git a/internals/cli/cmd_exec.go b/internals/cli/cmd_exec.go index fec1c5e2..b2f0c3d9 100644 --- a/internals/cli/cmd_exec.go +++ b/internals/cli/cmd_exec.go @@ -264,8 +264,14 @@ func execControlHandler(process *client.ExecProcess, terminal bool, stop <-chan } func init() { - info := AddCommand("exec", shortExecHelp, longExecHelp, func() flags.Commander { return &cmdExec{} }, execDescs, nil) - info.extra = func(cmd *flags.Command) { - cmd.PassAfterNonOption = true - } + AddCommand(&CmdInfo{ + Name: "exec", + ShortHelp: shortExecHelp, + LongHelp: longExecHelp, + Builder: func() flags.Commander { return &cmdExec{} }, + OptDescs: execDescs, + Extra: func(cmd *flags.Command) { + cmd.PassAfterNonOption = true + }, + }) } diff --git a/internals/cli/cmd_help.go b/internals/cli/cmd_help.go index cd923bf9..4f850ada 100644 --- a/internals/cli/cmd_help.go +++ b/internals/cli/cmd_help.go @@ -79,11 +79,16 @@ type cmdHelp struct { } func init() { - AddCommand("help", shortHelpHelp, longHelpHelp, func() flags.Commander { return &cmdHelp{} }, - map[string]string{ + AddCommand(&CmdInfo{ + Name: "help", + ShortHelp: shortHelpHelp, + LongHelp: longHelpHelp, + Builder: func() flags.Commander { return &cmdHelp{} }, + OptDescs: map[string]string{ "all": "Show a short summary of all commands", "man": "Generate the manpage", - }, nil) + }, + }) } func (cmd *cmdHelp) setParser(parser *flags.Parser) { @@ -164,8 +169,8 @@ type HelpCategory struct { Commands []string } -// helpCategories helps us by grouping commands -var helpCategories = []HelpCategory{{ +// HelpCategories helps us by grouping commands +var HelpCategories = []HelpCategory{{ Label: "Run", Description: "run pebble", Commands: []string{"run", "help", "version"}, @@ -191,11 +196,6 @@ var helpCategories = []HelpCategory{{ Commands: []string{"warnings", "okay"}, }} -// AddHelpCategory appends an existing help category to the Pebble help manual. -func AddHelpCategory(category HelpCategory) { - helpCategories = append(helpCategories, category) -} - var ( longPebbleDescription = strings.TrimSpace(` Pebble lets you control services and perform management actions on @@ -234,12 +234,12 @@ func printShortHelp() { printHelpHeader() fmt.Fprintln(Stdout) maxLen := 0 - for _, categ := range helpCategories { + for _, categ := range HelpCategories { if l := utf8.RuneCountInString(categ.Label); l > maxLen { maxLen = l } } - for _, categ := range helpCategories { + for _, categ := range HelpCategories { fmt.Fprintf(Stdout, "%*s: %s\n", maxLen+2, categ.Label, strings.Join(categ.Commands, ", ")) } printHelpFooter() @@ -249,7 +249,7 @@ func printShortHelp() { func printLongHelp(parser *flags.Parser) { printHelpHeader() maxLen := 0 - for _, categ := range helpCategories { + for _, categ := range HelpCategories { for _, command := range categ.Commands { if l := len(command); l > maxLen { maxLen = l @@ -264,7 +264,7 @@ func printLongHelp(parser *flags.Parser) { cmdLookup[cmd.Name] = cmd } - for _, categ := range helpCategories { + for _, categ := range HelpCategories { fmt.Fprintln(Stdout) fmt.Fprintf(Stdout, " %s (%s):\n", categ.Label, categ.Description) for _, name := range categ.Commands { diff --git a/internals/cli/cmd_help_test.go b/internals/cli/cmd_help_test.go index e04769a8..cdab5a2b 100644 --- a/internals/cli/cmd_help_test.go +++ b/internals/cli/cmd_help_test.go @@ -114,7 +114,7 @@ func (s *PebbleSuite) TestAddHelpCategory(c *C) { restore := fakeArgs("pebble") defer restore() - cli.AddHelpCategory(cli.HelpCategory{ + cli.HelpCategories = append(cli.HelpCategories, cli.HelpCategory{ Label: "Test category", Description: "Test description", Commands: []string{"run", "logs"}, diff --git a/internals/cli/cmd_logs.go b/internals/cli/cmd_logs.go index 43655f70..bbb32959 100644 --- a/internals/cli/cmd_logs.go +++ b/internals/cli/cmd_logs.go @@ -121,5 +121,11 @@ func notifyContext(parent context.Context, signals ...os.Signal) context.Context } func init() { - AddCommand("logs", shortLogsHelp, longLogsHelp, func() flags.Commander { return &cmdLogs{} }, logsDescs, nil) + AddCommand(&CmdInfo{ + Name: "logs", + ShortHelp: shortLogsHelp, + LongHelp: longLogsHelp, + Builder: func() flags.Commander { return &cmdLogs{} }, + OptDescs: logsDescs, + }) } diff --git a/internals/cli/cmd_ls.go b/internals/cli/cmd_ls.go index 39907669..1efb66d5 100644 --- a/internals/cli/cmd_ls.go +++ b/internals/cli/cmd_ls.go @@ -103,5 +103,11 @@ func parseGlob(path string) (parsedPath, parsedPattern string, err error) { } func init() { - AddCommand("ls", shortLsHelp, longLsHelp, func() flags.Commander { return &cmdLs{} }, merge(lsDescs, timeDescs), nil) + AddCommand(&CmdInfo{ + Name: "ls", + ShortHelp: shortLsHelp, + LongHelp: longLsHelp, + Builder: func() flags.Commander { return &cmdLs{} }, + OptDescs: merge(lsDescs, timeDescs), + }) } diff --git a/internals/cli/cmd_mkdir.go b/internals/cli/cmd_mkdir.go index 8d7cb068..f8417879 100644 --- a/internals/cli/cmd_mkdir.go +++ b/internals/cli/cmd_mkdir.go @@ -79,5 +79,11 @@ func (cmd *cmdMkdir) Execute(args []string) error { } func init() { - AddCommand("mkdir", shortMkdirHelp, longMkdirHelp, func() flags.Commander { return &cmdMkdir{} }, mkdirDescs, nil) + AddCommand(&CmdInfo{ + Name: "mkdir", + ShortHelp: shortMkdirHelp, + LongHelp: longMkdirHelp, + Builder: func() flags.Commander { return &cmdMkdir{} }, + OptDescs: mkdirDescs, + }) } diff --git a/internals/cli/cmd_plan.go b/internals/cli/cmd_plan.go index 0b74051a..1e1d89d2 100644 --- a/internals/cli/cmd_plan.go +++ b/internals/cli/cmd_plan.go @@ -43,5 +43,10 @@ func (cmd *cmdPlan) Execute(args []string) error { } func init() { - AddCommand("plan", shortPlanHelp, longPlanHelp, func() flags.Commander { return &cmdPlan{} }, nil, nil) + AddCommand(&CmdInfo{ + Name: "plan", + ShortHelp: shortPlanHelp, + LongHelp: longPlanHelp, + Builder: func() flags.Commander { return &cmdPlan{} }, + }) } diff --git a/internals/cli/cmd_replan.go b/internals/cli/cmd_replan.go index 3dd57c46..95606183 100644 --- a/internals/cli/cmd_replan.go +++ b/internals/cli/cmd_replan.go @@ -32,7 +32,13 @@ type cmdReplan struct { } func init() { - AddCommand("replan", shortReplanHelp, longReplanHelp, func() flags.Commander { return &cmdReplan{} }, waitDescs, nil) + AddCommand(&CmdInfo{ + Name: "replan", + ShortHelp: shortReplanHelp, + LongHelp: longReplanHelp, + Builder: func() flags.Commander { return &cmdReplan{} }, + OptDescs: waitDescs, + }) } func (cmd cmdReplan) Execute(args []string) error { diff --git a/internals/cli/cmd_restart.go b/internals/cli/cmd_restart.go index 5cf009d1..62329b09 100644 --- a/internals/cli/cmd_restart.go +++ b/internals/cli/cmd_restart.go @@ -33,7 +33,13 @@ type cmdRestart struct { } func init() { - AddCommand("restart", shortRestartHelp, longRestartHelp, func() flags.Commander { return &cmdRestart{} }, waitDescs, nil) + AddCommand(&CmdInfo{ + Name: "restart", + ShortHelp: shortRestartHelp, + LongHelp: longRestartHelp, + Builder: func() flags.Commander { return &cmdRestart{} }, + OptDescs: waitDescs, + }) } func (cmd cmdRestart) Execute(args []string) error { diff --git a/internals/cli/cmd_rm.go b/internals/cli/cmd_rm.go index 94cd3624..2f731cda 100644 --- a/internals/cli/cmd_rm.go +++ b/internals/cli/cmd_rm.go @@ -51,5 +51,11 @@ func (cmd *cmdRm) Execute(args []string) error { } func init() { - AddCommand("rm", shortRmHelp, longRmHelp, func() flags.Commander { return &cmdRm{} }, rmDescs, nil) + AddCommand(&CmdInfo{ + Name: "rm", + ShortHelp: shortRmHelp, + LongHelp: longRmHelp, + Builder: func() flags.Commander { return &cmdRm{} }, + OptDescs: rmDescs, + }) } diff --git a/internals/cli/cmd_run.go b/internals/cli/cmd_run.go index 9cc09068..430a0ecd 100644 --- a/internals/cli/cmd_run.go +++ b/internals/cli/cmd_run.go @@ -65,8 +65,13 @@ type cmdRun struct { } func init() { - AddCommand("run", shortRunHelp, longRunHelp, func() flags.Commander { return &cmdRun{} }, - sharedRunEnterOptsHelp, nil) + AddCommand(&CmdInfo{ + Name: "run", + ShortHelp: shortRunHelp, + LongHelp: longRunHelp, + Builder: func() flags.Commander { return &cmdRun{} }, + OptDescs: sharedRunEnterOptsHelp, + }) } func (rcmd *cmdRun) Execute(args []string) error { diff --git a/internals/cli/cmd_services.go b/internals/cli/cmd_services.go index d1009704..0f94cbcf 100644 --- a/internals/cli/cmd_services.go +++ b/internals/cli/cmd_services.go @@ -73,7 +73,11 @@ func (cmd *cmdServices) Execute(args []string) error { } func init() { - AddCommand("services", shortServicesHelp, longServicesHelp, - func() flags.Commander { return &cmdServices{} }, - timeDescs, nil) + AddCommand(&CmdInfo{ + Name: "services", + ShortHelp: shortServicesHelp, + LongHelp: longServicesHelp, + Builder: func() flags.Commander { return &cmdServices{} }, + OptDescs: timeDescs, + }) } diff --git a/internals/cli/cmd_signal.go b/internals/cli/cmd_signal.go index d92a1acf..f5721119 100644 --- a/internals/cli/cmd_signal.go +++ b/internals/cli/cmd_signal.go @@ -58,5 +58,10 @@ func (cmd *cmdSignal) Execute(args []string) error { } func init() { - AddCommand("signal", shortSignalHelp, longSignalHelp, func() flags.Commander { return &cmdSignal{} }, nil, nil) + AddCommand(&CmdInfo{ + Name: "signal", + ShortHelp: shortSignalHelp, + LongHelp: longSignalHelp, + Builder: func() flags.Commander { return &cmdSignal{} }, + }) } diff --git a/internals/cli/cmd_start.go b/internals/cli/cmd_start.go index d36eba40..4f474a57 100644 --- a/internals/cli/cmd_start.go +++ b/internals/cli/cmd_start.go @@ -34,7 +34,13 @@ type cmdStart struct { } func init() { - AddCommand("start", shortStartHelp, longStartHelp, func() flags.Commander { return &cmdStart{} }, waitDescs, nil) + AddCommand(&CmdInfo{ + Name: "start", + ShortHelp: shortStartHelp, + LongHelp: longStartHelp, + Builder: func() flags.Commander { return &cmdStart{} }, + OptDescs: waitDescs, + }) } func (cmd cmdStart) Execute(args []string) error { diff --git a/internals/cli/cmd_stop.go b/internals/cli/cmd_stop.go index 95473d65..db9f5d15 100644 --- a/internals/cli/cmd_stop.go +++ b/internals/cli/cmd_stop.go @@ -34,7 +34,13 @@ type cmdStop struct { } func init() { - AddCommand("stop", shortStopHelp, longStopHelp, func() flags.Commander { return &cmdStop{} }, waitDescs, nil) + AddCommand(&CmdInfo{ + Name: "stop", + ShortHelp: shortStopHelp, + LongHelp: longStopHelp, + Builder: func() flags.Commander { return &cmdStop{} }, + OptDescs: waitDescs, + }) } func (cmd cmdStop) Execute(args []string) error { diff --git a/internals/cli/cmd_version.go b/internals/cli/cmd_version.go index a36bb0c5..ecbe19a0 100644 --- a/internals/cli/cmd_version.go +++ b/internals/cli/cmd_version.go @@ -38,7 +38,13 @@ var versionDescs = map[string]string{ } func init() { - AddCommand("version", shortVersionHelp, longVersionHelp, func() flags.Commander { return &cmdVersion{} }, versionDescs, nil) + AddCommand(&CmdInfo{ + Name: "version", + ShortHelp: shortVersionHelp, + LongHelp: longVersionHelp, + Builder: func() flags.Commander { return &cmdVersion{} }, + OptDescs: versionDescs, + }) } func (cmd cmdVersion) Execute(args []string) error { diff --git a/internals/cli/cmd_warnings.go b/internals/cli/cmd_warnings.go index f12c32c1..2b5642fb 100644 --- a/internals/cli/cmd_warnings.go +++ b/internals/cli/cmd_warnings.go @@ -61,11 +61,22 @@ sufficient time has passed. ` func init() { - AddCommand("warnings", shortWarningsHelp, longWarningsHelp, func() flags.Commander { return &cmdWarnings{} }, merge(timeDescs, unicodeDescs, map[string]string{ - "all": "Show all warnings", - "verbose": "Show more information", - }), nil) - AddCommand("okay", shortOkayHelp, longOkayHelp, func() flags.Commander { return &cmdOkay{} }, nil, nil) + AddCommand(&CmdInfo{ + Name: "warnings", + ShortHelp: shortWarningsHelp, + LongHelp: longWarningsHelp, + Builder: func() flags.Commander { return &cmdWarnings{} }, + OptDescs: merge(timeDescs, unicodeDescs, map[string]string{ + "all": "Show all warnings", + "verbose": "Show more information", + }), + }) + AddCommand(&CmdInfo{ + Name: "okay", + ShortHelp: shortOkayHelp, + LongHelp: longOkayHelp, + Builder: func() flags.Commander { return &cmdOkay{} }, + }) } func (cmd *cmdWarnings) Execute(args []string) error {