diff --git a/help.go b/help.go index 068fce1..f5e155c 100644 --- a/help.go +++ b/help.go @@ -69,10 +69,16 @@ func (p *Parser) getAlignmentInfo() alignmentInfo { ret.terminalColumns = 80 } + isCmd := map[*Group]bool{} + p.eachCommand(func(cmd *Command) { + // TODO: have (*Command).showInHelp() to consider hidden vs active + isCmd[cmd.Group] = true + }, true) + var prevcmd *Command p.eachActiveGroup(func(c *Command, grp *Group) { - if !grp.showInHelp() { + if !(isCmd[grp] || grp.showInHelp()) { return } if c != prevcmd { diff --git a/help_test.go b/help_test.go index 6d7798d..c2d8a0b 100644 --- a/help_test.go +++ b/help_test.go @@ -563,10 +563,10 @@ func TestWroteHelp(t *testing.T) { isHelp bool } tests := map[string]testInfo{ - "No error": testInfo{value: nil, isHelp: false}, - "Plain error": testInfo{value: errors.New("an error"), isHelp: false}, - "ErrUnknown": testInfo{value: newError(ErrUnknown, "an error"), isHelp: false}, - "ErrHelp": testInfo{value: newError(ErrHelp, "an error"), isHelp: true}, + "No error": {value: nil, isHelp: false}, + "Plain error": {value: errors.New("an error"), isHelp: false}, + "ErrUnknown": {value: newError(ErrUnknown, "an error"), isHelp: false}, + "ErrHelp": {value: newError(ErrHelp, "an error"), isHelp: true}, } for name, test := range tests { @@ -578,3 +578,15 @@ func TestWroteHelp(t *testing.T) { }) } } + +func TestOnlyPositional(t *testing.T) { + type options struct { + Positional struct { + Bar string `description:"bar"` + } `positional-args:"yes"` + } + + var buf bytes.Buffer + NewParser(&options{}, 0).WriteHelp(&buf) + // just checking for no panic, at this point +}