diff --git a/usage.go b/usage.go index fc8b09a..4704183 100644 --- a/usage.go +++ b/usage.go @@ -117,6 +117,9 @@ func (p *Parser) writeUsageForCommand(w io.Writer, cmd *command) { } func printTwoCols(w io.Writer, left, help string, defaultVal string, envVal string) { + if left == "" { + return + } lhs := " " + left fmt.Fprint(w, lhs) if help != "" { diff --git a/usage_test.go b/usage_test.go index de40ebd..8e28dc5 100644 --- a/usage_test.go +++ b/usage_test.go @@ -328,3 +328,23 @@ Options: p.WriteHelp(&help) assert.Equal(t, expectedHelp, help.String()) } + +func TestUsageWithEnvOptions(t *testing.T) { + expectedHelp := `Usage: example [-s SHORT] + +Options: + -s SHORT [env: SHORT] + --help, -h display this help and exit +` + var args struct { + Short string `arg:"--,-s,env"` + EnvOnly string `arg:"--,env"` + EnvOnlyOverriden string `arg:"--,env:CUSTOM"` + } + + p, err := NewParser(Config{Program: "example"}, &args) + assert.NoError(t, err) + var help bytes.Buffer + p.WriteHelp(&help) + assert.Equal(t, expectedHelp, help.String()) +}