Merge pull request #161 from zyga/skip-help-2
Don't display description-less positional args in --help
diff --git a/help.go b/help.go
index c0b808d..aac78de 100644
--- a/help.go
+++ b/help.go
@@ -412,7 +412,14 @@
}
})
- if len(c.args) > 0 {
+ var args []*Arg
+ for _, arg := range c.args {
+ if arg.Description != "" {
+ args = append(args, arg)
+ }
+ }
+
+ if len(args) > 0 {
if c == p.Command {
fmt.Fprintf(wr, "\nArguments:\n")
} else {
@@ -421,7 +428,7 @@
maxlen := aligninfo.descriptionStart()
- for _, arg := range c.args {
+ for _, arg := range args {
prefix := strings.Repeat(" ", paddingBeforeOption)
fmt.Fprintf(wr, "%s%s", prefix, arg.Name)
diff --git a/help_test.go b/help_test.go
index 33d21bf..1dcbe7f 100644
--- a/help_test.go
+++ b/help_test.go
@@ -53,8 +53,9 @@
} `command:"hidden-command" description:"A hidden command" hidden:"yes"`
Args struct {
- Filename string `positional-arg-name:"filename" description:"A filename"`
- Number int `positional-arg-name:"num" description:"A number"`
+ Filename string `positional-arg-name:"filename" description:"A filename"`
+ Number int `positional-arg-name:"num" description:"A number"`
+ HiddenInHelp float32 `positional-arg-name:"hidden-in-help" required:"yes"`
} `positional-args:"yes"`
}
@@ -84,7 +85,8 @@
if runtime.GOOS == "windows" {
expected = `Usage:
- TestHelp [OPTIONS] [filename] [num] <command>
+ TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <command>
+
Application Options:
/v, /verbose Show verbose debug information
@@ -129,7 +131,7 @@
`
} else {
expected = `Usage:
- TestHelp [OPTIONS] [filename] [num] <command>
+ TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <command>
Application Options:
-v, --verbose Show verbose debug information
diff --git a/ini_test.go b/ini_test.go
index dd7fe33..dfe49ce 100644
--- a/ini_test.go
+++ b/ini_test.go
@@ -21,7 +21,7 @@
expected string
}{
{
- []string{"-vv", "--intmap=a:2", "--intmap", "b:3", "filename", "0", "command"},
+ []string{"-vv", "--intmap=a:2", "--intmap", "b:3", "filename", "0", "3.14", "command"},
IniDefault,
`[Application Options]
; Show verbose debug information
@@ -42,7 +42,7 @@
`,
},
{
- []string{"-vv", "--intmap=a:2", "--intmap", "b:3", "filename", "0", "command"},
+ []string{"-vv", "--intmap=a:2", "--intmap", "b:3", "filename", "0", "3.14", "command"},
IniDefault | IniIncludeDefaults,
`[Application Options]
; Show verbose debug information
@@ -104,7 +104,7 @@
`,
},
{
- []string{"filename", "0", "command"},
+ []string{"filename", "0", "3.14", "command"},
IniDefault | IniIncludeDefaults | IniCommentDefaults,
`[Application Options]
; Show verbose debug information
@@ -164,7 +164,7 @@
`,
},
{
- []string{"--default=New value", "--default-array=New value", "--default-map=new:value", "filename", "0", "command"},
+ []string{"--default=New value", "--default-array=New value", "--default-map=new:value", "filename", "0", "3.14", "command"},
IniDefault | IniIncludeDefaults | IniCommentDefaults,
`[Application Options]
; Show verbose debug information