From f88547bbf5976d875e0233baea0bf848f4e8c1c2 Mon Sep 17 00:00:00 2001 From: Haotian Date: Tue, 7 Feb 2023 09:28:18 -0800 Subject: [PATCH] fix(cli): update plural resource mentions in generated help texts (#2918) --- .../credentiallibraries.gen.go | 2 +- .../vault-generic_credentiallibraries.gen.go | 2 +- ...ssh-certificate_credentiallibraries.gen.go | 2 +- .../vault_credentiallibraries.gen.go | 2 +- internal/cmd/common/help.go | 37 ++++++++++--------- internal/cmd/gencli/templates.go | 8 +++- 6 files changed, 31 insertions(+), 22 deletions(-) diff --git a/internal/cmd/commands/credentiallibrariescmd/credentiallibraries.gen.go b/internal/cmd/commands/credentiallibrariescmd/credentiallibraries.gen.go index 419f6c014d..d48ebc03b9 100644 --- a/internal/cmd/commands/credentiallibrariescmd/credentiallibraries.gen.go +++ b/internal/cmd/commands/credentiallibrariescmd/credentiallibraries.gen.go @@ -126,7 +126,7 @@ func (c *Command) Run(args []string) int { c.plural = "credential library" switch c.Func { case "list": - c.plural = "credential librarys" + c.plural = "credential libraries" } f := c.Flags() diff --git a/internal/cmd/commands/credentiallibrariescmd/vault-generic_credentiallibraries.gen.go b/internal/cmd/commands/credentiallibrariescmd/vault-generic_credentiallibraries.gen.go index 0aaa8b27d6..9e01caa5fc 100644 --- a/internal/cmd/commands/credentiallibrariescmd/vault-generic_credentiallibraries.gen.go +++ b/internal/cmd/commands/credentiallibrariescmd/vault-generic_credentiallibraries.gen.go @@ -112,7 +112,7 @@ func (c *VaultGenericCommand) Run(args []string) int { c.plural = "vault-generic-type credential library" switch c.Func { case "list": - c.plural = "vault-generic-type credential librarys" + c.plural = "vault-generic-type credential libraries" } f := c.Flags() diff --git a/internal/cmd/commands/credentiallibrariescmd/vault-ssh-certificate_credentiallibraries.gen.go b/internal/cmd/commands/credentiallibrariescmd/vault-ssh-certificate_credentiallibraries.gen.go index bdc8919390..ac6a0de59c 100644 --- a/internal/cmd/commands/credentiallibrariescmd/vault-ssh-certificate_credentiallibraries.gen.go +++ b/internal/cmd/commands/credentiallibrariescmd/vault-ssh-certificate_credentiallibraries.gen.go @@ -112,7 +112,7 @@ func (c *VaultSshCertificateCommand) Run(args []string) int { c.plural = "vault-ssh-certificate-type credential library" switch c.Func { case "list": - c.plural = "vault-ssh-certificate-type credential librarys" + c.plural = "vault-ssh-certificate-type credential libraries" } f := c.Flags() diff --git a/internal/cmd/commands/credentiallibrariescmd/vault_credentiallibraries.gen.go b/internal/cmd/commands/credentiallibrariescmd/vault_credentiallibraries.gen.go index 7fdb932eba..9ae6e542c4 100644 --- a/internal/cmd/commands/credentiallibrariescmd/vault_credentiallibraries.gen.go +++ b/internal/cmd/commands/credentiallibrariescmd/vault_credentiallibraries.gen.go @@ -112,7 +112,7 @@ func (c *VaultCommand) Run(args []string) int { c.plural = "vault-type credential library" switch c.Func { case "list": - c.plural = "vault-type credential librarys" + c.plural = "vault-type credential libraries" } f := c.Flags() diff --git a/internal/cmd/common/help.go b/internal/cmd/common/help.go index 9dcb2f53ce..8b9e477ef1 100644 --- a/internal/cmd/common/help.go +++ b/internal/cmd/common/help.go @@ -46,25 +46,25 @@ func HelpMap(resType string) map[string]func() string { return map[string]func() string{ "base": func() string { return base.WrapForHelpText(subtype([]string{ - "Usage: boundary {{hyphentype}}s [sub command] [options] [args]", + "Usage: boundary {{hyphentypes}} [sub command] [options] [args]", "", " This command allows operations on Boundary {{type}} resources. Example:", "", " Create {{articletype}}:", "", - ` $ boundary {{hyphentype}}s create -name prodops -description "For ProdOps usage"`, + ` $ boundary {{hyphentypes}} create -name prodops -description "For ProdOps usage"`, "", - " Please see the {{hyphentype}}s subcommand help for detailed usage information.", + " Please see the {{hyphentypes}} subcommand help for detailed usage information.", }, resType, prefixMap)) }, "create": func() string { return base.WrapForHelpText(subtype([]string{ - "Usage: boundary {{hyphentype}}s create [options] [args]", + "Usage: boundary {{hyphentypes}} create [options] [args]", "", " Create {{articletype}}. Example:", "", - ` $ boundary {{hyphentype}}s create -name prodops -description "{{uppertype}} for ProdOps"`, + ` $ boundary {{hyphentypes}} create -name prodops -description "{{uppertype}} for ProdOps"`, "", "", }, resType, prefixMap)) @@ -72,11 +72,11 @@ func HelpMap(resType string) map[string]func() string { "update": func() string { return base.WrapForHelpText(subtype([]string{ - "Usage: boundary {{hyphentype}}s update [options] [args]", + "Usage: boundary {{hyphentypes}} update [options] [args]", "", " Update {{articletype}} given its ID. Example:", "", - ` $ boundary {{hyphentype}}s update -id {{prefix}}_1234567890 -name "devops" -description "{{uppertype}} for DevOps"`, + ` $ boundary {{hyphentypes}} update -id {{prefix}}_1234567890 -name "devops" -description "{{uppertype}} for DevOps"`, "", "", }, resType, prefixMap)) @@ -84,11 +84,11 @@ func HelpMap(resType string) map[string]func() string { "read": func() string { return base.WrapForHelpText(subtype([]string{ - "Usage: boundary {{hyphentype}}s read [options] [args]", + "Usage: boundary {{hyphentypes}} read [options] [args]", "", " Read {{articletype}} given its ID. Example:", "", - ` $ boundary {{hyphentype}}s read -id {{prefix}}_1234567890`, + ` $ boundary {{hyphentypes}} read -id {{prefix}}_1234567890`, "", "", }, resType, prefixMap)) @@ -96,11 +96,11 @@ func HelpMap(resType string) map[string]func() string { "delete": func() string { return base.WrapForHelpText(subtype([]string{ - "Usage: boundary {{hyphentype}}s delete [options] [args]", + "Usage: boundary {{hyphentypes}} delete [options] [args]", "", " Delete {{articletype}} given its ID. Example:", "", - ` $ boundary {{hyphentype}}s delete -id {{prefix}}_1234567890`, + ` $ boundary {{hyphentypes}} delete -id {{prefix}}_1234567890`, "", "", }, resType, prefixMap)) @@ -108,11 +108,11 @@ func HelpMap(resType string) map[string]func() string { "list": func() string { return base.WrapForHelpText(subtype([]string{ - "Usage: boundary {{hyphentype}}s list [options] [args]", + "Usage: boundary {{hyphentypes}} list [options] [args]", "", - " List {{type}}s within an enclosing scope or resource. Example:", + " List {{pluraltypes}} within an enclosing scope or resource. Example:", "", - ` $ boundary {{hyphentype}}s list`, + ` $ boundary {{hyphentypes}} list`, "", "", }, resType, prefixMap)) @@ -121,7 +121,8 @@ func HelpMap(resType string) map[string]func() string { } func subtype(in []string, resType string, prefixMap map[string]string) []string { - hyphenType := strings.ReplaceAll(resType, " ", "-") + hyphenTypePlural := resource.Map[strings.ReplaceAll(resType, " ", "-")].PluralString() + pluralTypes := strings.ReplaceAll(hyphenTypePlural, "-", " ") articleType := resType switch resType[0] { case 'a', 'e', 'i', 'o': @@ -135,8 +136,10 @@ func subtype(in []string, resType string, prefixMap map[string]string) []string strings.Replace( strings.Replace( strings.Replace( - v, "{{hyphentype}}", hyphenType, -1), - "{{type}}", resType, -1), + strings.Replace( + v, "{{hyphentypes}}", hyphenTypePlural, -1), + "{{type}}", resType, -1), + "{{pluraltypes}}", pluralTypes, -1), "{{uppertype}}", textproto.CanonicalMIMEHeaderKey(resType), -1), "{{prefix}}", prefixMap[resType], -1), "{{articletype}}", articleType, -1) diff --git a/internal/cmd/gencli/templates.go b/internal/cmd/gencli/templates.go index 7251ae21cd..498b342f13 100644 --- a/internal/cmd/gencli/templates.go +++ b/internal/cmd/gencli/templates.go @@ -8,6 +8,7 @@ import ( "path/filepath" "text/template" + "github.com/hashicorp/boundary/internal/types/resource" "github.com/hashicorp/go-secure-stdlib/strutil" "github.com/iancoleman/strcase" ) @@ -67,6 +68,10 @@ func hasAction(in []string, action string) bool { return strutil.StrListContains(in, action) } +func pluralString(in string) string { + return lowerSpaceCase(resource.Map[in].PluralString()) +} + var cmdTemplate = template.Must(template.New("").Funcs( template.FuncMap{ "camelCase": camelCase, @@ -75,6 +80,7 @@ var cmdTemplate = template.Must(template.New("").Funcs( "kebabCase": kebabCase, "lowerSpaceCase": lowerSpaceCase, "hasAction": hasAction, + "pluralString": pluralString, }, ).Parse(`{{ $input := . }} // Code generated by "make cli"; DO NOT EDIT. @@ -273,7 +279,7 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int { c.plural = "{{ if .SubActionPrefix }}{{ kebabCase .SubActionPrefix }}-type {{ end }}{{ lowerSpaceCase .ResourceType }}" switch c.Func { case "list": - c.plural = "{{ if .SubActionPrefix }}{{ kebabCase .SubActionPrefix }}-type {{ end }}{{ lowerSpaceCase .ResourceType }}s" + c.plural = "{{ if .SubActionPrefix }}{{ kebabCase .SubActionPrefix }}-type {{ end }}{{ pluralString .ResourceType }}" } f := c.Flags()