From 80752e9a243debea419832cc64bde81442caa98f Mon Sep 17 00:00:00 2001 From: irenarindos Date: Wed, 15 Jun 2022 10:18:40 -0400 Subject: [PATCH] cli(workers): Add extra help func --- internal/cmd/commands.go | 5 +++++ internal/cmd/commands/workerscmd/funcs.go | 21 +++++++++++++++++++ .../cmd/commands/workerscmd/workers.gen.go | 2 +- internal/cmd/common/help.go | 1 + internal/cmd/gencli/input.go | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/internal/cmd/commands.go b/internal/cmd/commands.go index 466a027520..e465c37d01 100644 --- a/internal/cmd/commands.go +++ b/internal/cmd/commands.go @@ -1030,6 +1030,11 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) { }, nil }, + "workers": func() (cli.Command, error) { + return &workerscmd.Command{ + Command: base.NewCommand(ui), + }, nil + }, "workers create": func() (cli.Command, error) { return &workerscmd.Command{ Command: base.NewCommand(ui), diff --git a/internal/cmd/commands/workerscmd/funcs.go b/internal/cmd/commands/workerscmd/funcs.go index 1e959eb3a9..693c1d9f31 100644 --- a/internal/cmd/commands/workerscmd/funcs.go +++ b/internal/cmd/commands/workerscmd/funcs.go @@ -9,6 +9,27 @@ import ( "github.com/hashicorp/boundary/internal/cmd/base" ) +func (c *Command) extraHelpFunc(helpMap map[string]func() string) string { + var helpStr string + switch c.Func { + case "": + return base.WrapForHelpText([]string{ + "Usage: boundary workers [sub command] [options] [args]", + "", + " This command allows operations on Boundary worker resources. Example:", + "", + " Read a worker:", + "", + ` $ boundary workers read -id w_1234567890`, + "", + " Please see the workers subcommand help for detailed usage information.", + }) + default: + helpStr = helpMap[c.Func]() + } + return helpStr + c.Flags().Help() +} + func (c *Command) printListTable(items []*workers.Worker) string { if len(items) == 0 { return "No workers found" diff --git a/internal/cmd/commands/workerscmd/workers.gen.go b/internal/cmd/commands/workerscmd/workers.gen.go index a75ad588c9..d9434dae63 100644 --- a/internal/cmd/commands/workerscmd/workers.gen.go +++ b/internal/cmd/commands/workerscmd/workers.gen.go @@ -79,7 +79,7 @@ func (c *Command) Help() string { default: - helpStr = helpMap["base"]() + helpStr = c.extraHelpFunc(helpMap) } diff --git a/internal/cmd/common/help.go b/internal/cmd/common/help.go index cea87b3563..20f6eb0266 100644 --- a/internal/cmd/common/help.go +++ b/internal/cmd/common/help.go @@ -38,6 +38,7 @@ func HelpMap(resType string) map[string]func() string { resource.Host.String(): "h", resource.Session.String(): "s", resource.Target.String(): "t", + resource.Worker.String(): "w", } return map[string]func() string{ "base": func() string { diff --git a/internal/cmd/gencli/input.go b/internal/cmd/gencli/input.go index 062a161782..e6960b0883 100644 --- a/internal/cmd/gencli/input.go +++ b/internal/cmd/gencli/input.go @@ -458,6 +458,7 @@ var inputStructs = map[string][]*cmdInfo{ ResourceType: resource.Worker.String(), Pkg: "workers", StdActions: []string{"read", "update", "delete", "list"}, + HasExtraHelpFunc: true, HasId: true, Container: "Scope", HasName: true,