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

Take operands in account when configuring automatic help #6

Merged
merged 1 commit into from
Oct 7, 2019
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# VSCode config
.vscode

# idea
.idea
2 changes: 1 addition & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (cmd *Cmd) setupHelp() {
return
}

if (len(cmd.optentries) > 0 || len(cmd.commands) > 0) && cmd.shortopt["-h"] == nil {
if (len(cmd.optentries) > 0 || len(cmd.commands) > 0 || len(cmd.operands) > 0) && cmd.shortopt["-h"] == nil {
cmd.Bool("help", "h", false, "Show this help message.")
}
}
10 changes: 10 additions & 0 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func TestArgs(t *testing.T) {
}
}

func TestHelpMessageWithOperands(t *testing.T) {
app := libcmd.NewApp("app", "some brief description")
app.AddOperand("src", "?")
app.AddOperand("dst", "*")

if err := compareHelpOutput(app, []string{"-h", "test", "test2"}, "testdata/help-message-with-operands.golden"); err != nil {
t.Error(err)
}
}

func TestArgsPartial(t *testing.T) {
app := libcmd.NewApp("app", "some brief description")
app.Long = "this is a very long description"
Expand Down
2 changes: 1 addition & 1 deletion opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (cmd *Cmd) doParse(args []string) error {
return unknownArgErr{arg: arg.name}
}

// some argument types have autmatic values in certain cases
// some argument types have automatic values in certain cases
// fill them in, if necessary
entry.fillAutoValue(arg)

Expand Down
7 changes: 7 additions & 0 deletions testdata/help-message-with-operands.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
app - some brief description

USAGE: app [OPTIONS...] [src] [dst...]

Options:
-h, --help
Show this help message.