mcfg: ensure all usages end in a period when printing help to cli

This commit is contained in:
Brian Picciano 2019-02-02 19:35:30 -05:00
parent 6adfbdbcfb
commit f02f2904b0
2 changed files with 12 additions and 7 deletions

View File

@ -175,8 +175,13 @@ func (cli SourceCLI) printHelp(w io.Writer, pM map[string]Param) {
fmt.Fprintf(w, " (Default: %s)", defVal)
}
fmt.Fprintf(w, "\n")
if p.Usage != "" {
fmt.Fprintln(w, "\t"+p.Usage)
if usage := p.Usage; usage != "" {
// make all usages end with a period, because I say so
usage = strings.TrimSpace(usage)
if !strings.HasSuffix(usage, ".") {
usage += "."
}
fmt.Fprintln(w, "\t"+usage)
}
}
fmt.Fprintf(w, "\n")

View File

@ -15,8 +15,8 @@ import (
func TestSourceCLIHelp(t *T) {
ctx := mctx.New()
Int(ctx, "foo", 5, "Test int param")
Bool(ctx, "bar", "Test bool param")
Int(ctx, "foo", 5, "Test int param ") // trailing space should be trimmed
Bool(ctx, "bar", "Test bool param.")
String(ctx, "baz", "baz", "Test string param")
RequiredString(ctx, "baz2", "")
RequiredString(ctx, "baz3", "")
@ -33,13 +33,13 @@ func TestSourceCLIHelp(t *T) {
--baz3 (Required)
--bar (Flag)
Test bool param
Test bool param.
--baz (Default: "baz")
Test string param
Test string param.
--foo (Default: 5)
Test int param
Test int param.
`
assert.Equal(t, exp, buf.String())