From 603b0582d7d873c17174920a5cc17e9d2e56bd9d Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 9 Oct 2020 20:26:48 -0400 Subject: [PATCH] Fix CLI help output and make more consistent (#605) --- internal/cmd/commands/accounts/account.go | 24 ++++++----- internal/cmd/commands/accounts/password.go | 3 +- .../cmd/commands/authenticate/password.go | 3 +- .../cmd/commands/authmethods/authmethod.go | 34 ++++++--------- internal/cmd/commands/authmethods/password.go | 14 +++--- .../cmd/commands/authtokens/authtokens.go | 4 +- internal/cmd/commands/groups/funcs.go | 8 +++- internal/cmd/commands/groups/group.go | 12 ++---- .../cmd/commands/hostcatalogs/hostcatalog.go | 33 ++++++-------- internal/cmd/commands/hostcatalogs/static.go | 13 +++--- internal/cmd/commands/hosts/host.go | 14 +++--- internal/cmd/commands/hosts/static.go | 8 +--- internal/cmd/commands/hostsets/hostset.go | 43 +++++++++---------- internal/cmd/commands/hostsets/static.go | 9 ++-- internal/cmd/commands/roles/funcs.go | 2 +- internal/cmd/commands/roles/role.go | 6 +-- internal/cmd/commands/scopes/scope.go | 28 ++++++------ internal/cmd/commands/sessions/session.go | 7 +-- internal/cmd/commands/targets/funcs.go | 16 +++++++ internal/cmd/commands/targets/target.go | 21 ++++++--- internal/cmd/commands/targets/tcp.go | 3 +- internal/cmd/commands/users/user.go | 12 ++---- internal/cmd/common/help.go | 2 +- 23 files changed, 157 insertions(+), 162 deletions(-) diff --git a/internal/cmd/commands/accounts/account.go b/internal/cmd/commands/accounts/account.go index a44bb2f04..a62039c65 100644 --- a/internal/cmd/commands/accounts/account.go +++ b/internal/cmd/commands/accounts/account.go @@ -32,10 +32,10 @@ type Command struct { func (c *Command) Synopsis() string { switch c.Func { - case "create": - return "Create account resources within Boundary" - case "update": - return "Update account resources within Boundary" + case "set-password": + return "Directly set the password on an account resource" + case "change-password": + return "Change the password on an account resource" default: return common.SynopsisFunc(c.Func, "account") } @@ -98,6 +98,8 @@ func (c *Command) Help() string { " Set the password on a password-type account:", "", ` $ boundary accounts set-password -id apw_1234567890 -password `, + "", + "", }) case "change-password": helpStr = base.WrapForHelpText([]string{ @@ -108,6 +110,8 @@ func (c *Command) Help() string { " Change the password on a password-type account:", "", ` $ boundary accounts change-password -id apw_1234567890 -current-password -new-password `, + "", + "", }) default: helpStr = helpMap[c.Func]() @@ -116,14 +120,14 @@ func (c *Command) Help() string { } func (c *Command) Flags() *base.FlagSets { - set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - - f := set.NewFlagSet("Command Options") - - if len(flagsMap[c.Func]) > 0 { - common.PopulateCommonFlags(c.Command, f, resource.Account.String(), flagsMap[c.Func]) + if len(flagsMap[c.Func]) == 0 { + return c.FlagSet(base.FlagSetNone) } + set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) + f := set.NewFlagSet("Command Options") + common.PopulateCommonFlags(c.Command, f, resource.Account.String(), flagsMap[c.Func]) + for _, name := range flagsMap[c.Func] { switch name { case "password": diff --git a/internal/cmd/commands/accounts/password.go b/internal/cmd/commands/accounts/password.go index 87aece7a8..1712f22e0 100644 --- a/internal/cmd/commands/accounts/password.go +++ b/internal/cmd/commands/accounts/password.go @@ -29,7 +29,7 @@ type PasswordCommand struct { } func (c *PasswordCommand) Synopsis() string { - return fmt.Sprintf("%s a password-type account within Boundary", textproto.CanonicalMIMEHeaderKey(c.Func)) + return fmt.Sprintf("%s a password-type account", textproto.CanonicalMIMEHeaderKey(c.Func)) } var passwordFlagsMap = map[string][]string{ @@ -67,7 +67,6 @@ func (c *PasswordCommand) Help() string { func (c *PasswordCommand) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - f := set.NewFlagSet("Command Options") if len(passwordFlagsMap[c.Func]) > 0 { diff --git a/internal/cmd/commands/authenticate/password.go b/internal/cmd/commands/authenticate/password.go index 4fddbdb19..c337e05ed 100644 --- a/internal/cmd/commands/authenticate/password.go +++ b/internal/cmd/commands/authenticate/password.go @@ -44,12 +44,13 @@ func (c *PasswordCommand) Help() string { " Invoke the password auth method to authenticate the Boundary CLI:", "", ` $ boundary authenticate password -auth-method-id ampw_1234567890 -login-name foo -password "bar"`, + "", + "", }) + c.Flags().Help() } func (c *PasswordCommand) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - f := set.NewFlagSet("Command Options") f.StringVar(&base.StringVar{ diff --git a/internal/cmd/commands/authmethods/authmethod.go b/internal/cmd/commands/authmethods/authmethod.go index 61087dbba..08731c2fc 100644 --- a/internal/cmd/commands/authmethods/authmethod.go +++ b/internal/cmd/commands/authmethods/authmethod.go @@ -24,14 +24,7 @@ type Command struct { } func (c *Command) Synopsis() string { - switch c.Func { - case "create": - return "Create auth-method resources within Boundary" - case "update": - return "Update auth-method resources within Boundary" - default: - return common.SynopsisFunc(c.Func, "auth-method") - } + return common.SynopsisFunc(c.Func, "auth method") } var flagsMap = map[string][]string{ @@ -41,16 +34,16 @@ var flagsMap = map[string][]string{ } func (c *Command) Help() string { - helpMap := common.HelpMap("auth-method") + helpMap := common.HelpMap("auth method") var helpStr string switch c.Func { case "": return base.WrapForHelpText([]string{ "Usage: boundary auth-methods [sub command] [options] [args]", "", - " This command allows operations on Boundary auth-method resources. Example:", + " This command allows operations on Boundary auth method resources. Example:", "", - " Read an auth-method:", + " Read an auth method:", "", ` $ boundary auth-methods read -id ampw_1234567890`, "", @@ -60,9 +53,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary auth-methods create [type] [sub command] [options] [args]", "", - " This command allows create operations on Boundary auth-method resources. Example:", + " This command allows create operations on Boundary auth method resources. Example:", "", - " Create a password-type auth-method:", + " Create a password-type auth method:", "", ` $ boundary auth-methods create password -name prodops -description "For ProdOps usage"`, "", @@ -72,9 +65,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary auth-methods update [type] [sub command] [options] [args]", "", - " This command allows update operations on Boundary auth-method resources. Example:", + " This command allows update operations on Boundary auth method resources. Example:", "", - " Update a password-type auth-method:", + " Update a password-type auth method:", "", ` $ boundary auth-methods update password -id ampw_1234567890 -name devops -description "For DevOps usage"`, "", @@ -87,13 +80,14 @@ func (c *Command) Help() string { } func (c *Command) Flags() *base.FlagSets { - set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - - if len(flagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - common.PopulateCommonFlags(c.Command, f, resource.AuthMethod.String(), flagsMap[c.Func]) + if len(flagsMap[c.Func]) == 0 { + return c.FlagSet(base.FlagSetNone) } + set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) + f := set.NewFlagSet("Command Options") + common.PopulateCommonFlags(c.Command, f, resource.AuthMethod.String(), flagsMap[c.Func]) + return set } diff --git a/internal/cmd/commands/authmethods/password.go b/internal/cmd/commands/authmethods/password.go index 551ace316..166af01a5 100644 --- a/internal/cmd/commands/authmethods/password.go +++ b/internal/cmd/commands/authmethods/password.go @@ -27,7 +27,7 @@ type PasswordCommand struct { } func (c *PasswordCommand) Synopsis() string { - return fmt.Sprintf("%s a password-type auth-method within Boundary", textproto.CanonicalMIMEHeaderKey(c.Func)) + return fmt.Sprintf("%s a password type auth-method", textproto.CanonicalMIMEHeaderKey(c.Func)) } var passwordFlagsMap = map[string][]string{ @@ -42,7 +42,7 @@ func (c *PasswordCommand) Help() string { info = base.WrapForHelpText([]string{ "Usage: boundary auth-methods create password [options] [args]", "", - " Create a password-type auth-method. Example:", + " Create a password-type auth method. Example:", "", ` $ boundary auth-methods create password -name prodops -description "Password auth-method for ProdOps"`, "", @@ -53,7 +53,7 @@ func (c *PasswordCommand) Help() string { info = base.WrapForHelpText([]string{ "Usage: boundary auth-methods update password [options] [args]", "", - " Update a password-type auth-method given its ID. Example:", + " Update a password-type auth method given its ID. Example:", "", ` $ boundary auth-methods update password -id ampw_1234567890 -name "devops" -description "Password auth-method for DevOps"`, "", @@ -66,12 +66,10 @@ func (c *PasswordCommand) Help() string { func (c *PasswordCommand) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - if len(passwordFlagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - common.PopulateCommonFlags(c.Command, f, "password-type auth-method", passwordFlagsMap[c.Func]) - } + f := set.NewFlagSet("Command Options") + common.PopulateCommonFlags(c.Command, f, "password-type auth method", passwordFlagsMap[c.Func]) - f := set.NewFlagSet("Password Auth-Method Options") + f = set.NewFlagSet("Password Auth-Method Options") addPasswordFlags(c, f) return set diff --git a/internal/cmd/commands/authtokens/authtokens.go b/internal/cmd/commands/authtokens/authtokens.go index 3df12bf20..e6e5d4549 100644 --- a/internal/cmd/commands/authtokens/authtokens.go +++ b/internal/cmd/commands/authtokens/authtokens.go @@ -25,7 +25,7 @@ type Command struct { } func (c *Command) Synopsis() string { - return common.SynopsisFunc(c.Func, "auth-token") + return common.SynopsisFunc(c.Func, "auth token") } var flagsMap = map[string][]string{ @@ -35,7 +35,7 @@ var flagsMap = map[string][]string{ } func (c *Command) Help() string { - helpMap := common.HelpMap("auth-token") + helpMap := common.HelpMap("auth token") if c.Func == "" { return helpMap["base"]() } diff --git a/internal/cmd/commands/groups/funcs.go b/internal/cmd/commands/groups/funcs.go index e67c4fd19..8f0e20e5e 100644 --- a/internal/cmd/commands/groups/funcs.go +++ b/internal/cmd/commands/groups/funcs.go @@ -22,7 +22,7 @@ func memberSynopsisFunc(inFunc string) string { case strings.HasPrefix(inFunc, "remove"): in = "Remove users from" } - return wordwrap.WrapString(fmt.Sprintf("%s a group within Boundary", in), base.TermWidth) + return wordwrap.WrapString(fmt.Sprintf("%s a group", in), base.TermWidth) } func addMembersHelp() string { @@ -32,6 +32,8 @@ func addMembersHelp() string { ` Adds members (users) to a group given its ID. The "user" flag can be specified multiple times. Example:`, "", ` $ boundary groups add-members -id g_1234567890 -user u_1234567890`, + "", + "", }) } @@ -42,6 +44,8 @@ func setMembersHelp() string { ` Sets the complete set of members (users) on a group given its ID. The "user" flag can be specified multiple times. Example:`, "", ` $ boundary groups set-principals -id g_1234567890 -user u_anon -user u_1234567890`, + "", + "", }) } @@ -52,6 +56,8 @@ func removeMembersHelp() string { ` Removes members (users) from a group given its ID. The "user" flag can be specified multiple times. Example:`, "", ` $ boundary groups remove-members -id g_1234567890 -user u_1234567890`, + "", + "", }) } diff --git a/internal/cmd/commands/groups/group.go b/internal/cmd/commands/groups/group.go index ed60d813c..92588ef26 100644 --- a/internal/cmd/commands/groups/group.go +++ b/internal/cmd/commands/groups/group.go @@ -26,12 +26,11 @@ type Command struct { func (c *Command) Synopsis() string { switch c.Func { - case "", "create", "update", "read", "delete", "list": - return common.SynopsisFunc(c.Func, "group") case "add-members", "set-members", "remove-members": return memberSynopsisFunc(c.Func) + default: + return common.SynopsisFunc(c.Func, "group") } - return "" } var helpMap = func() map[string]func() string { @@ -63,11 +62,8 @@ func (c *Command) Help() string { func (c *Command) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - - if len(flagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - populateFlags(c, f, flagsMap[c.Func]) - } + f := set.NewFlagSet("Command Options") + populateFlags(c, f, flagsMap[c.Func]) return set } diff --git a/internal/cmd/commands/hostcatalogs/hostcatalog.go b/internal/cmd/commands/hostcatalogs/hostcatalog.go index 1f94af938..0ac9ac55b 100644 --- a/internal/cmd/commands/hostcatalogs/hostcatalog.go +++ b/internal/cmd/commands/hostcatalogs/hostcatalog.go @@ -24,14 +24,7 @@ type Command struct { } func (c *Command) Synopsis() string { - switch c.Func { - case "create": - return "Create host-catalog resources within Boundary" - case "update": - return "Update host-catalog resources within Boundary" - default: - return common.SynopsisFunc(c.Func, "host-catalog") - } + return common.SynopsisFunc(c.Func, "host catalog") } var flagsMap = map[string][]string{ @@ -41,16 +34,16 @@ var flagsMap = map[string][]string{ } func (c *Command) Help() string { - helpMap := common.HelpMap("host-catalog") + helpMap := common.HelpMap("host catalog") var helpStr string switch c.Func { case "": return base.WrapForHelpText([]string{ "Usage: boundary host-catalogs [sub command] [options] [args]", "", - " This command allows operations on Boundary host-catalog resources. Example:", + " This command allows operations on Boundary host catalog resources. Example:", "", - " Read a host-catalog:", + " Read a host catalog:", "", ` $ boundary host-catalogs read -id hcst_1234567890`, "", @@ -60,9 +53,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary host-catalogs create [type] [sub command] [options] [args]", "", - " This command allows create operations on Boundary host-catalog resources. Example:", + " This command allows create operations on Boundary host catalog resources. Example:", "", - " Create a static-type host-catalog:", + " Create a static-type host catalog:", "", ` $ boundary host-catalogs create static -name prodops -description "For ProdOps usage"`, "", @@ -72,9 +65,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary host-catalogs update [type] [sub command] [options] [args]", "", - " This command allows update operations on Boundary host-catalog resources. Example:", + " This command allows update operations on Boundary host catalog resources. Example:", "", - " Update a static-type host-catalog:", + " Update a static-type host catalog:", "", ` $ boundary host-catalogs update static -id hcst_1234567890 -name devops -description "For DevOps usage"`, "", @@ -87,12 +80,14 @@ func (c *Command) Help() string { } func (c *Command) Flags() *base.FlagSets { + if len(flagsMap[c.Func]) == 0 { + return c.FlagSet(base.FlagSetNone) + } + set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - if len(flagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - common.PopulateCommonFlags(c.Command, f, resource.HostCatalog.String(), flagsMap[c.Func]) - } + f := set.NewFlagSet("Command Options") + common.PopulateCommonFlags(c.Command, f, resource.HostCatalog.String(), flagsMap[c.Func]) return set } diff --git a/internal/cmd/commands/hostcatalogs/static.go b/internal/cmd/commands/hostcatalogs/static.go index 7ef8e1c03..7cdd26588 100644 --- a/internal/cmd/commands/hostcatalogs/static.go +++ b/internal/cmd/commands/hostcatalogs/static.go @@ -23,7 +23,7 @@ type StaticCommand struct { } func (c *StaticCommand) Synopsis() string { - return fmt.Sprintf("%s a static-type host-catalog within Boundary", textproto.CanonicalMIMEHeaderKey(c.Func)) + return fmt.Sprintf("%s a static-type host catalog", textproto.CanonicalMIMEHeaderKey(c.Func)) } var staticFlagsMap = map[string][]string{ @@ -38,7 +38,7 @@ func (c *StaticCommand) Help() string { info = base.WrapForHelpText([]string{ "Usage: boundary host-catalogs create static [options] [args]", "", - " Create a static-type host-catalog. Example:", + " Create a static-type host catalog. Example:", "", ` $ boundary host-catalogs create static -name prodops -description "Static host-catalog for ProdOps"`, "", @@ -49,7 +49,7 @@ func (c *StaticCommand) Help() string { info = base.WrapForHelpText([]string{ "Usage: boundary host-catalogs update static [options] [args]", "", - " Update a static-type host-catalog given its ID. Example:", + " Update a static-type host catalog given its ID. Example:", "", ` $ boundary host-catalogs update static -id hcst_1234567890 -name "devops" -description "Static host-catalog for DevOps"`, "", @@ -61,11 +61,8 @@ func (c *StaticCommand) Help() string { func (c *StaticCommand) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - - if len(staticFlagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - common.PopulateCommonFlags(c.Command, f, "static-type host-catalog", staticFlagsMap[c.Func]) - } + f := set.NewFlagSet("Command Options") + common.PopulateCommonFlags(c.Command, f, "static-type host catalog", staticFlagsMap[c.Func]) return set } diff --git a/internal/cmd/commands/hosts/host.go b/internal/cmd/commands/hosts/host.go index b20f332f9..a2451263d 100644 --- a/internal/cmd/commands/hosts/host.go +++ b/internal/cmd/commands/hosts/host.go @@ -24,14 +24,7 @@ type Command struct { } func (c *Command) Synopsis() string { - switch c.Func { - case "create": - return "Create host resources within Boundary" - case "update": - return "Update host resources within Boundary" - default: - return common.SynopsisFunc(c.Func, "host") - } + return common.SynopsisFunc(c.Func, "host") } var flagsMap = map[string][]string{ @@ -87,8 +80,11 @@ func (c *Command) Help() string { } func (c *Command) Flags() *base.FlagSets { - set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) + if len(flagsMap[c.Func]) == 0 { + return c.FlagSet(base.FlagSetNone) + } + set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) f := set.NewFlagSet("Command Options") common.PopulateCommonFlags(c.Command, f, resource.Host.String(), flagsMap[c.Func]) diff --git a/internal/cmd/commands/hosts/static.go b/internal/cmd/commands/hosts/static.go index f07cfa44b..c87d7c0b7 100644 --- a/internal/cmd/commands/hosts/static.go +++ b/internal/cmd/commands/hosts/static.go @@ -25,7 +25,7 @@ type StaticCommand struct { } func (c *StaticCommand) Synopsis() string { - return fmt.Sprintf("%s a static-type host within Boundary", textproto.CanonicalMIMEHeaderKey(c.Func)) + return fmt.Sprintf("%s a static-type host", textproto.CanonicalMIMEHeaderKey(c.Func)) } var staticFlagsMap = map[string][]string{ @@ -63,12 +63,8 @@ func (c *StaticCommand) Help() string { func (c *StaticCommand) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - f := set.NewFlagSet("Command Options") - - if len(staticFlagsMap[c.Func]) > 0 { - common.PopulateCommonFlags(c.Command, f, "static-type host", staticFlagsMap[c.Func]) - } + common.PopulateCommonFlags(c.Command, f, "static-type host", staticFlagsMap[c.Func]) f = set.NewFlagSet("Static Host Options") diff --git a/internal/cmd/commands/hostsets/hostset.go b/internal/cmd/commands/hostsets/hostset.go index 23964ff6a..b10db85b6 100644 --- a/internal/cmd/commands/hostsets/hostset.go +++ b/internal/cmd/commands/hostsets/hostset.go @@ -27,18 +27,14 @@ type Command struct { func (c *Command) Synopsis() string { switch c.Func { - case "create": - return "Create host-set resources within Boundary" - case "update": - return "Update host-set resources within Boundary" case "add-hosts": - return "Add hosts to the specified host-set" + return "Add hosts to the specified host set" case "remove-hosts": - return "Remove hosts from the specified host-set" + return "Remove hosts from the specified host set" case "set-hosts": - return "Set the full contents of the hosts on the specified host-set" + return "Set the full contents of the hosts on the specified host set" default: - return common.SynopsisFunc(c.Func, "host-set") + return common.SynopsisFunc(c.Func, "host set") } } @@ -52,16 +48,16 @@ var flagsMap = map[string][]string{ } func (c *Command) Help() string { - helpMap := common.HelpMap("host-set") + helpMap := common.HelpMap("host set") var helpStr string switch c.Func { case "": return base.WrapForHelpText([]string{ "Usage: boundary host-sets [sub command] [options] [args]", "", - " This command allows operations on Boundary host-set resources. Example:", + " This command allows operations on Boundary host set resources. Example:", "", - " Read a host-set:", + " Read a host set:", "", ` $ boundary host-sets read -id hsst_1234567890`, "", @@ -71,9 +67,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary host-sets create [type] [sub command] [options] [args]", "", - " This command allows create operations on Boundary host-set resources. Example:", + " This command allows create operations on Boundary host set resources. Example:", "", - " Create a static-type host-set:", + " Create a static-type host set:", "", ` $ boundary host-sets create static -name prodops -description "For ProdOps usage"`, "", @@ -83,9 +79,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary host-sets update [type] [sub command] [options] [args]", "", - " This command allows update operations on Boundary host-set resources. Example:", + " This command allows update operations on Boundary host set resources. Example:", "", - " Update a static-type host-set:", + " Update a static-type host set:", "", ` $ boundary host-sets update static -id hsst_1234567890 -name devops -description "For DevOps usage"`, "", @@ -95,9 +91,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary host-sets add-hosts [sub command] [options] [args]", "", - " This command allows adding hosts to host-set resources, if the types match and the operation is allowed by the given host-set type. Example:", + " This command allows adding hosts to host set resources, if the types match and the operation is allowed by the given host set type. Example:", "", - " Add static-type hosts to a static-type host-set:", + " Add static-type hosts to a static-type host set:", "", ` $ boundary host-sets add-hosts -id hsst_1234567890 -host hst_1234567890 -host hst_0987654321`, }) @@ -105,9 +101,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary host-sets remove-hosts [sub command] [options] [args]", "", - " This command allows removing hosts from host-set resources, if the types match and the operation is allowed by the given host-set type. Example:", + " This command allows removing hosts from host set resources, if the types match and the operation is allowed by the given host set type. Example:", "", - " Remove static-type hosts from a static-type host-set:", + " Remove static-type hosts from a static-type host set:", "", ` $ boundary host-sets remove-hosts -id hsst_1234567890 -host hst_0987654321`, }) @@ -115,9 +111,9 @@ func (c *Command) Help() string { helpStr = base.WrapForHelpText([]string{ "Usage: boundary host-sets set-hosts [sub command] [options] [args]", "", - " This command allows setting the complete set of hosts on host-set resources, if the types match and the operation is allowed by the given host-set type. Example:", + " This command allows setting the complete set of hosts on host set resources, if the types match and the operation is allowed by the given host set type. Example:", "", - " Set the complete set of static-type hosts on a static-type host-set:", + " Set the complete set of static-type hosts on a static-type host set:", "", ` $ boundary host-sets remove-hosts -id hsst_1234567890 -host hst_1234567890`, }) @@ -128,8 +124,11 @@ func (c *Command) Help() string { } func (c *Command) Flags() *base.FlagSets { - set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) + if len(flagsMap[c.Func]) == 0 { + return c.FlagSet(base.FlagSetNone) + } + set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) f := set.NewFlagSet("Command Options") common.PopulateCommonFlags(c.Command, f, resource.HostSet.String(), flagsMap[c.Func]) diff --git a/internal/cmd/commands/hostsets/static.go b/internal/cmd/commands/hostsets/static.go index 434786de8..915ce886a 100644 --- a/internal/cmd/commands/hostsets/static.go +++ b/internal/cmd/commands/hostsets/static.go @@ -23,7 +23,7 @@ type StaticCommand struct { } func (c *StaticCommand) Synopsis() string { - return fmt.Sprintf("%s a static-type host-set within Boundary", textproto.CanonicalMIMEHeaderKey(c.Func)) + return fmt.Sprintf("%s a static-type host set", textproto.CanonicalMIMEHeaderKey(c.Func)) } var staticFlagsMap = map[string][]string{ @@ -38,7 +38,7 @@ func (c *StaticCommand) Help() string { info = base.WrapForHelpText([]string{ "Usage: boundary host-sets create static [options] [args]", "", - " Create a static-type host-set. Example:", + " Create a static-type host set. Example:", "", ` $ boundary host-sets create static -name prodops -description "Static host-set for ProdOps"`, "", @@ -49,7 +49,7 @@ func (c *StaticCommand) Help() string { info = base.WrapForHelpText([]string{ "Usage: boundary host-sets update static [options] [args]", "", - " Update a static-type host-set given its ID. Example:", + " Update a static-type host set given its ID. Example:", "", ` $ boundary host-sets update static -id hsst_1234567890 -name "devops" -description "Static host-set for DevOps"`, "", @@ -61,9 +61,8 @@ func (c *StaticCommand) Help() string { func (c *StaticCommand) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - f := set.NewFlagSet("Command Options") - common.PopulateCommonFlags(c.Command, f, "static-type host-set", staticFlagsMap[c.Func]) + common.PopulateCommonFlags(c.Command, f, "static-type host set", staticFlagsMap[c.Func]) return set } diff --git a/internal/cmd/commands/roles/funcs.go b/internal/cmd/commands/roles/funcs.go index 10bd31f59..de433809e 100644 --- a/internal/cmd/commands/roles/funcs.go +++ b/internal/cmd/commands/roles/funcs.go @@ -26,7 +26,7 @@ func principalsGrantsSynopsisFunc(inFunc string, principals bool) string { case strings.HasPrefix(inFunc, "remove"): in = fmt.Sprintf("Remove %s from", switchStr) } - return wordwrap.WrapString(fmt.Sprintf("%s a role within Boundary", in), base.TermWidth) + return wordwrap.WrapString(fmt.Sprintf("%s a role", in), base.TermWidth) } func addPrincipalsHelp() string { diff --git a/internal/cmd/commands/roles/role.go b/internal/cmd/commands/roles/role.go index 729dae4fc..08bf32a60 100644 --- a/internal/cmd/commands/roles/role.go +++ b/internal/cmd/commands/roles/role.go @@ -75,11 +75,9 @@ func (c *Command) Help() string { func (c *Command) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) + f := set.NewFlagSet("Command Options") + populateFlags(c, f, flagsMap[c.Func]) - if len(flagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - populateFlags(c, f, flagsMap[c.Func]) - } return set } diff --git a/internal/cmd/commands/scopes/scope.go b/internal/cmd/commands/scopes/scope.go index 1e9ac0ea2..17df8cc3c 100644 --- a/internal/cmd/commands/scopes/scope.go +++ b/internal/cmd/commands/scopes/scope.go @@ -48,22 +48,20 @@ func (c *Command) Help() string { func (c *Command) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) + f := set.NewFlagSet("Command Options") + common.PopulateCommonFlags(c.Command, f, resource.Scope.String(), flagsMap[c.Func]) - if len(flagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - common.PopulateCommonFlags(c.Command, f, resource.Scope.String(), flagsMap[c.Func]) - if c.Func == "create" { - f.BoolVar(&base.BoolVar{ - Name: "skip-admin-role-creation", - Target: &c.flagSkipAdminRoleCreation, - Usage: "If set, a role granting the current user access to administer the newly-created scope will not automatically be created", - }) - f.BoolVar(&base.BoolVar{ - Name: "skip-default-role-creation", - Target: &c.flagSkipDefaultRoleCreation, - Usage: "If set, a role granting the anonymous user access to log into auth methods and a few other actions within the newly-created scope will not automatically be created", - }) - } + if c.Func == "create" { + f.BoolVar(&base.BoolVar{ + Name: "skip-admin-role-creation", + Target: &c.flagSkipAdminRoleCreation, + Usage: "If set, a role granting the current user access to administer the newly-created scope will not automatically be created", + }) + f.BoolVar(&base.BoolVar{ + Name: "skip-default-role-creation", + Target: &c.flagSkipDefaultRoleCreation, + Usage: "If set, a role granting the anonymous user access to log into auth methods and a few other actions within the newly-created scope will not automatically be created", + }) } return set diff --git a/internal/cmd/commands/sessions/session.go b/internal/cmd/commands/sessions/session.go index d55f650ae..adbb65fed 100644 --- a/internal/cmd/commands/sessions/session.go +++ b/internal/cmd/commands/sessions/session.go @@ -67,11 +67,8 @@ func (c *Command) Help() string { func (c *Command) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - - if len(flagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - common.PopulateCommonFlags(c.Command, f, resource.Session.String(), flagsMap[c.Func]) - } + f := set.NewFlagSet("Command Options") + common.PopulateCommonFlags(c.Command, f, resource.Session.String(), flagsMap[c.Func]) return set } diff --git a/internal/cmd/commands/targets/funcs.go b/internal/cmd/commands/targets/funcs.go index 08ac457f4..a3726b28e 100644 --- a/internal/cmd/commands/targets/funcs.go +++ b/internal/cmd/commands/targets/funcs.go @@ -1,13 +1,29 @@ package targets import ( + "fmt" + "strings" "time" "github.com/hashicorp/boundary/api/scopes" "github.com/hashicorp/boundary/api/targets" "github.com/hashicorp/boundary/internal/cmd/base" + "github.com/mitchellh/go-wordwrap" ) +func hostSetSynopsisFunc(inFunc string) string { + var in string + switch { + case strings.HasPrefix(inFunc, "add"): + in = "Add host sets to" + case strings.HasPrefix(inFunc, "set"): + in = "Set the full contents of the host sets on" + case strings.HasPrefix(inFunc, "remove"): + in = "Remove host sets from" + } + return wordwrap.WrapString(fmt.Sprintf("%s a target", in), base.TermWidth) +} + func generateTargetTableOutput(in *targets.Target) string { nonAttributeMap := map[string]interface{}{ "ID": in.Id, diff --git a/internal/cmd/commands/targets/target.go b/internal/cmd/commands/targets/target.go index 432c556df..225256798 100644 --- a/internal/cmd/commands/targets/target.go +++ b/internal/cmd/commands/targets/target.go @@ -29,10 +29,10 @@ type Command struct { func (c *Command) Synopsis() string { switch c.Func { - case "create": - return "Create target resources within Boundary" - case "update": - return "Update target resources within Boundary" + case "add-host-sets", "set-host-sets", "remove-host-sets": + return hostSetSynopsisFunc(c.Func) + case "authorize-session": + return "Request session authorization against the target" default: return common.SynopsisFunc(c.Func, "target") } @@ -97,6 +97,8 @@ func (c *Command) Help() string { " Add host-set resources to a tcp-type target:", "", ` $ boundary targets add-host-sets -id ttcp_1234567890 -host-set hsst_1234567890 -host-set hsst_0987654321`, + "", + "", }) case "remove-host-sets": helpStr = base.WrapForHelpText([]string{ @@ -107,6 +109,8 @@ func (c *Command) Help() string { " Remove host-set resources from a tcp-type target:", "", ` $ boundary targets add-host-sets -id ttcp_1234567890 -host hsst_1234567890 -host-set hsst_0987654321`, + "", + "", }) case "set-host-sets": helpStr = base.WrapForHelpText([]string{ @@ -117,6 +121,8 @@ func (c *Command) Help() string { " Set host-set resources on a tcp-type target:", "", ` $ boundary targets set-host-sets -id ttcp_1234567890 -host-set hsst_1234567890`, + "", + "", }) case "authorize-session": helpStr = base.WrapForHelpText([]string{ @@ -127,6 +133,8 @@ func (c *Command) Help() string { " Set host-set resources on a tcp-type target:", "", ` $ boundary targets authorize-session -id ttcp_1234567890`, + "", + "", }) default: helpStr = helpMap[c.Func]() @@ -135,8 +143,11 @@ func (c *Command) Help() string { } func (c *Command) Flags() *base.FlagSets { - set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) + if len(flagsMap[c.Func]) == 0 { + return c.FlagSet(base.FlagSetNone) + } + set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) f := set.NewFlagSet("Command Options") common.PopulateCommonFlags(c.Command, f, resource.Target.String(), flagsMap[c.Func]) diff --git a/internal/cmd/commands/targets/tcp.go b/internal/cmd/commands/targets/tcp.go index 63d16eac3..5f8f584ae 100644 --- a/internal/cmd/commands/targets/tcp.go +++ b/internal/cmd/commands/targets/tcp.go @@ -28,7 +28,7 @@ type TcpCommand struct { } func (c *TcpCommand) Synopsis() string { - return fmt.Sprintf("%s a tcp-type target within Boundary", textproto.CanonicalMIMEHeaderKey(c.Func)) + return fmt.Sprintf("%s a tcp-type target", textproto.CanonicalMIMEHeaderKey(c.Func)) } var tcpFlagsMap = map[string][]string{ @@ -66,7 +66,6 @@ func (c *TcpCommand) Help() string { func (c *TcpCommand) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - f := set.NewFlagSet("Command Options") common.PopulateCommonFlags(c.Command, f, "tcp-type target", tcpFlagsMap[c.Func]) diff --git a/internal/cmd/commands/users/user.go b/internal/cmd/commands/users/user.go index f5f40ef17..e2af0a6e4 100644 --- a/internal/cmd/commands/users/user.go +++ b/internal/cmd/commands/users/user.go @@ -26,12 +26,11 @@ type Command struct { func (c *Command) Synopsis() string { switch c.Func { - case "", "create", "update", "read", "delete", "list": - return common.SynopsisFunc(c.Func, "user") case "add-accounts", "set-accounts", "remove-accounts": return accountSynopsisFunc(c.Func) + default: + return common.SynopsisFunc(c.Func, "user") } - return "" } var helpMap = func() map[string]func() string { @@ -63,11 +62,8 @@ func (c *Command) Help() string { func (c *Command) Flags() *base.FlagSets { set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat) - - if len(flagsMap[c.Func]) > 0 { - f := set.NewFlagSet("Command Options") - populateFlags(c, f, flagsMap[c.Func]) - } + f := set.NewFlagSet("Command Options") + populateFlags(c, f, flagsMap[c.Func]) return set } diff --git a/internal/cmd/common/help.go b/internal/cmd/common/help.go index 0e06821c0..f5a0ed255 100644 --- a/internal/cmd/common/help.go +++ b/internal/cmd/common/help.go @@ -21,7 +21,7 @@ func SynopsisFunc(inFunc, resType string) string { default: articleType = fmt.Sprintf("a %s", articleType) } - return wordwrap.WrapString(fmt.Sprintf("%s %s within Boundary", textproto.CanonicalMIMEHeaderKey(inFunc), articleType), base.TermWidth) + return wordwrap.WrapString(fmt.Sprintf("%s %s", textproto.CanonicalMIMEHeaderKey(inFunc), articleType), base.TermWidth) } func HelpMap(resType string) map[string]func() string {