Skip to content
Closed
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: 8 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ type Command struct {
// but accepted if entered manually.
ArgAliases []string

// ArgDescriptionForUseLine will be appended to the usage line of a command
// line of a command when printing help or generating docs
// to allow you to describe the meaning of the arguments the command takes.
ArgDescriptionForUseLine string

// BashCompletionFunction is custom functions used by the bash autocompletion generator.
BashCompletionFunction string

Expand Down Expand Up @@ -1180,6 +1185,9 @@ func (c *Command) UseLine() string {
if c.HasAvailableFlags() && !strings.Contains(useline, "[flags]") {
useline += " [flags]"
}
if c.ArgDescriptionForUseLine != "" {
useline += " " + c.ArgDescriptionForUseLine
}
return useline
}

Expand Down
10 changes: 10 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,16 @@ func TestFlagsInUsage(t *testing.T) {
checkStringContains(t, output, "[flags]")
}

func TestArgsInUsage(t *testing.T) {
rootCmd := &Command{Use: "root", Args: NoArgs, ArgDescriptionForUseLine: "name [arg...]", Run: func(*Command, []string) {}}
output, err := executeCommand(rootCmd, "--help")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}

checkStringContains(t, output, "[flags] name [arg...]")
}

func TestHelpExecutedOnNonRunnableChild(t *testing.T) {
rootCmd := &Command{Use: "root", Run: emptyRun}
childCmd := &Command{Use: "child", Long: "Long description"}
Expand Down