Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not skip groups that are commands when working out alignment #281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 16 additions & 4 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gah, my gofmt-on-save is forever doing this

}

for name, test := range tests {
Expand All @@ -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
}