Skip to content

Commit

Permalink
This fixes issue #269 and #270
Browse files Browse the repository at this point in the history
It changes the definition of `(*Option).canCli()` to also check
whether an option is hidden.

There's still some work to be done in this area as a group with no
non-hidden options will also not render right, but I'll get to that
later.
  • Loading branch information
chipaca committed Sep 22, 2018
1 parent 1c38ed7 commit 14b8957
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (p *Parser) WriteHelp(writer io.Writer) {
}

for _, info := range grp.options {
if !info.canCli() || info.Hidden {
if !info.canCli() {
continue
}

Expand Down
20 changes: 17 additions & 3 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 {
Expand All @@ -47,6 +49,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"`
Expand Down Expand Up @@ -88,7 +94,7 @@ func TestHelp(t *testing.T) {

if runtime.GOOS == "windows" {
expected = `Usage:
TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <command>
TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <bommand | command>
Application Options:
/v, /verbose Show verbose debug information
Expand Down Expand Up @@ -131,11 +137,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] <command>
TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <bommand | command>
Application Options:
-v, --verbose Show verbose debug information
Expand Down Expand Up @@ -177,6 +184,7 @@ Arguments:
num: A number
Available commands:
bommand A command with only hidden options
command A command (aliases: cm, cmd)
`
}
Expand All @@ -196,7 +204,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)
Expand Down Expand Up @@ -274,6 +284,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
Expand Down
2 changes: 1 addition & 1 deletion man.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func writeManPageOptions(wr io.Writer, grp *Group) {
}

for _, opt := range group.options {
if !opt.canCli() || opt.Hidden {
if !opt.canCli() {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion option.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (option *Option) set(value *string) error {
}

func (option *Option) canCli() bool {
return option.ShortName != 0 || len(option.LongName) != 0
return !option.Hidden && (option.ShortName != 0 || len(option.LongName) != 0)
}

func (option *Option) canArgument() bool {
Expand Down

0 comments on commit 14b8957

Please sign in to comment.