Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hyphenation of resource subcommand output #689

Merged
merged 4 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

Canonical reference for changes, improvements, and bugfixes for Boundary.

## vNext

### What's New

### Improvements

### Bug Fixes

* cli: Fix hyphenation in help output for resources with compound names
([Issue](https://github.com/hashicorp/boundary/issues/686))
([PR](https://github.com/hashicorp/boundary/pull/689))

## v0.1.0

v0.1.0 is the first release of Boundary. As a result there are no changes, improvements, or bugfixes from past versions.
v0.1.0 is the first release of Boundary. As a result there are no changes, improvements, or bugfixes from past versions.
31 changes: 17 additions & 14 deletions internal/cmd/common/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,73 +42,73 @@ func HelpMap(resType string) map[string]func() string {
return map[string]func() string{
"base": func() string {
return base.WrapForHelpText(subType([]string{
"Usage: boundary {{type}}s [sub command] [options] [args]",
"Usage: boundary {{hyphentype}}s [sub command] [options] [args]",
"",
" This command allows operations on Boundary {{type}} resources. Example:",
"",
" Create {{articletype}}:",
"",
` $ boundary {{type}}s create -name prodops -description "For ProdOps usage"`,
` $ boundary {{hyphentype}}s create -name prodops -description "For ProdOps usage"`,
"",
" Please see the {{type}}s subcommand help for detailed usage information.",
" Please see the {{hyphentype}}s subcommand help for detailed usage information.",
}, resType, prefixMap))
},

"create": func() string {
return base.WrapForHelpText(subType([]string{
"Usage: boundary {{type}}s create [options] [args]",
"Usage: boundary {{hyphentype}}s create [options] [args]",
"",
" Create {{articletype}}. Example:",
"",
` $ boundary {{type}}s create -name prodops -description "{{uppertype}} for ProdOps"`,
` $ boundary {{hyphentype}}s create -name prodops -description "{{uppertype}} for ProdOps"`,
"",
"",
}, resType, prefixMap))
},

"update": func() string {
return base.WrapForHelpText(subType([]string{
"Usage: boundary {{type}}s update [options] [args]",
"Usage: boundary {{hyphentype}}s update [options] [args]",
"",
" Update {{articletype}} given its ID. Example:",
"",
` $ boundary {{type}}s update -id {{prefix}}_1234567890 -name "devops" -description "{{uppertype}} for DevOps"`,
` $ boundary {{hyphentype}}s update -id {{prefix}}_1234567890 -name "devops" -description "{{uppertype}} for DevOps"`,
"",
"",
}, resType, prefixMap))
},

"read": func() string {
return base.WrapForHelpText(subType([]string{
"Usage: boundary {{type}}s read [options] [args]",
"Usage: boundary {{hyphentype}}s read [options] [args]",
"",
" Read {{articletype}} given its ID. Example:",
"",
` $ boundary {{type}}s read -id {{prefix}}_1234567890`,
` $ boundary {{hyphentype}}s read -id {{prefix}}_1234567890`,
"",
"",
}, resType, prefixMap))
},

"delete": func() string {
return base.WrapForHelpText(subType([]string{
"Usage: boundary {{type}}s delete [options] [args]",
"Usage: boundary {{hyphentype}}s delete [options] [args]",
"",
" Delete {{articletype}} given its ID. Example:",
"",
` $ boundary {{type}}s delete -id {{prefix}}_1234567890`,
` $ boundary {{hyphentype}}s delete -id {{prefix}}_1234567890`,
"",
"",
}, resType, prefixMap))
},

"list": func() string {
return base.WrapForHelpText(subType([]string{
"Usage: boundary {{type}}s list [options] [args]",
"Usage: boundary {{hyphentype}}s list [options] [args]",
"",
" List {{type}}s within an enclosing scope or resource. Example:",
"",
` $ boundary {{type}}s list`,
` $ boundary {{hyphentype}}s list`,
"",
"",
}, resType, prefixMap))
Expand All @@ -117,6 +117,7 @@ func HelpMap(resType string) map[string]func() string {
}

func subType(in []string, resType string, prefixMap map[string]string) []string {
hyphenType := strings.ReplaceAll(resType, " ", "-")
articleType := resType
switch resType[0] {
case 'a', 'e', 'i', 'o':
Expand All @@ -130,7 +131,9 @@ func subType(in []string, resType string, prefixMap map[string]string) []string
strings.Replace(
strings.Replace(
strings.Replace(
v, "{{type}}", resType, -1),
strings.Replace(
v, "{{hyphentype}}", hyphenType, -1),
"{{type}}", resType, -1),
"{{uppertype}}", textproto.CanonicalMIMEHeaderKey(resType), -1),
"{{prefix}}", prefixMap[resType], -1),
"{{articletype}}", articleType, -1)
Expand Down