Skip right column if the left is empty
This commit is contained in:
parent
04c3fdbd80
commit
438a91dba1
3
usage.go
3
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) {
|
func printTwoCols(w io.Writer, left, help string, defaultVal string, envVal string) {
|
||||||
|
if left == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
lhs := " " + left
|
lhs := " " + left
|
||||||
fmt.Fprint(w, lhs)
|
fmt.Fprint(w, lhs)
|
||||||
if help != "" {
|
if help != "" {
|
||||||
|
|
|
@ -328,3 +328,23 @@ Options:
|
||||||
p.WriteHelp(&help)
|
p.WriteHelp(&help)
|
||||||
assert.Equal(t, expectedHelp, help.String())
|
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())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue