fix(cli): update plural resource mentions in generated help texts (#2918)

pull/2929/head
Haotian 3 years ago committed by GitHub
parent eea5e80fa2
commit f88547bbf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()

@ -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()

@ -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()

@ -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()

@ -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)

@ -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()

Loading…
Cancel
Save