diff --git a/command.go b/command.go index 486bacb..879465d 100644 --- a/command.go +++ b/command.go @@ -438,7 +438,7 @@ func (c *Command) match(name string) bool { return false } -func (c *Command) hasCliOptions() bool { +func (c *Command) hasHelpOptions() bool { ret := false c.eachGroup(func(g *Group) { @@ -447,7 +447,7 @@ func (c *Command) hasCliOptions() bool { } for _, opt := range g.options { - if opt.canCli() { + if opt.showInHelp() { ret = true } } diff --git a/help.go b/help.go index 4743cc9..1b3b1ee 100644 --- a/help.go +++ b/help.go @@ -79,7 +79,7 @@ func (p *Parser) getAlignmentInfo() alignmentInfo { } for _, info := range grp.options { - if !info.canCli() { + if !info.showInHelp() { continue } @@ -305,7 +305,7 @@ func (p *Parser) WriteHelp(writer io.Writer) { } } else if us, ok := allcmd.data.(Usage); ok { usage = us.Usage() - } else if allcmd.hasCliOptions() { + } else if allcmd.hasHelpOptions() { usage = fmt.Sprintf("[%s-OPTIONS]", allcmd.Name) } @@ -393,7 +393,7 @@ func (p *Parser) WriteHelp(writer io.Writer) { } for _, info := range grp.options { - if !info.canCli() || info.Hidden { + if !info.showInHelp() { continue } diff --git a/help_test.go b/help_test.go index 7faea34..1ed4397 100644 --- a/help_test.go +++ b/help_test.go @@ -27,6 +27,8 @@ type helpOptions struct { OptionWithChoices string `long:"opt-with-choices" value-name:"choice" choice:"dog" choice:"cat" description:"Option with choices"` Hidden string `long:"hidden" description:"Hidden option" hidden:"yes"` + HiddenOptionWithVeryLongName bool `long:"this-hidden-option-has-a-ridiculously-long-name" hidden:"yes"` + OnlyIni string `ini-name:"only-ini" description:"Option only available in ini"` Other struct { @@ -48,6 +50,10 @@ type helpOptions struct { } `group:"Subsubgroup" namespace:"sap"` } `group:"Subgroup" namespace:"sip"` + Bommand struct { + Hidden bool `long:"hidden" description:"A hidden option" hidden:"yes"` + } `command:"bommand" description:"A command with only hidden options"` + Command struct { ExtraVerbose []bool `long:"extra-verbose" description:"Use for extra verbosity"` } `command:"command" alias:"cm" alias:"cmd" description:"A command"` @@ -89,7 +95,7 @@ func TestHelp(t *testing.T) { if runtime.GOOS == "windows" { expected = `Usage: - TestHelp [OPTIONS] [filename] [num] [hidden-in-help] + TestHelp [OPTIONS] [filename] [num] [hidden-in-help] Application Options: /v, /verbose Show verbose debug information @@ -132,11 +138,12 @@ Arguments: num: A number Available commands: + bommand A command with only hidden options command A command (aliases: cm, cmd) ` } else { expected = `Usage: - TestHelp [OPTIONS] [filename] [num] [hidden-in-help] + TestHelp [OPTIONS] [filename] [num] [hidden-in-help] Application Options: -v, --verbose Show verbose debug information @@ -178,6 +185,7 @@ Arguments: num: A number Available commands: + bommand A command with only hidden options command A command (aliases: cm, cmd) ` } @@ -197,7 +205,9 @@ func TestMan(t *testing.T) { p.LongDescription = "This is a somewhat `longer' description of what this does" p.AddGroup("Application Options", "The application options", &opts) - p.Commands()[0].LongDescription = "Longer `command' description" + for _, cmd := range p.Commands() { + cmd.LongDescription = fmt.Sprintf("Longer `%s' description", cmd.Name) + } var buf bytes.Buffer p.WriteManPage(&buf) @@ -275,6 +285,10 @@ Not hidden inside group \fB\fB\-\-sip.sap.opt\fR\fP This is a subsubgroup option .SH COMMANDS +.SS bommand +A command with only hidden options + +Longer \fBbommand\fP description .SS command A command diff --git a/man.go b/man.go index c2cebae..e3cc723 100644 --- a/man.go +++ b/man.go @@ -54,7 +54,7 @@ func writeManPageOptions(wr io.Writer, grp *Group) { } for _, opt := range group.options { - if !opt.canCli() || opt.Hidden { + if !opt.showInHelp() { continue } @@ -148,12 +148,12 @@ func writeManPageCommand(wr io.Writer, name string, root *Command, command *Comm var usage string if us, ok := command.data.(Usage); ok { usage = us.Usage() - } else if command.hasCliOptions() { + } else if command.hasHelpOptions() { usage = fmt.Sprintf("[%s-OPTIONS]", command.Name) } var pre string - if root.hasCliOptions() { + if root.hasHelpOptions() { pre = fmt.Sprintf("%s [OPTIONS] %s", root.Name, command.Name) } else { pre = fmt.Sprintf("%s %s", root.Name, command.Name) diff --git a/option.go b/option.go index c681c39..8e306d9 100644 --- a/option.go +++ b/option.go @@ -280,8 +280,8 @@ func (option *Option) set(value *string) error { return convert("", option.value, option.tag) } -func (option *Option) canCli() bool { - return option.ShortName != 0 || len(option.LongName) != 0 +func (option *Option) showInHelp() bool { + return !option.Hidden && (option.ShortName != 0 || len(option.LongName) != 0) } func (option *Option) canArgument() bool {