From f02f2904b07a35163a763ff88bda3c7a15fda477 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 2 Feb 2019 19:35:30 -0500 Subject: [PATCH] mcfg: ensure all usages end in a period when printing help to cli --- mcfg/cli.go | 9 +++++++-- mcfg/cli_test.go | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mcfg/cli.go b/mcfg/cli.go index ff0b556..28b1ed5 100644 --- a/mcfg/cli.go +++ b/mcfg/cli.go @@ -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") diff --git a/mcfg/cli_test.go b/mcfg/cli_test.go index b696687..09d3960 100644 --- a/mcfg/cli_test.go +++ b/mcfg/cli_test.go @@ -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())