Skip to content

Commit

Permalink
feat(command): adding args to use line
Browse files Browse the repository at this point in the history
Signed-off-by: danmx <daniel.iziourov@elastic.co>
  • Loading branch information
danmx committed Aug 18, 2022
1 parent dbf85f6 commit 1a75560
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ type Command struct {
// line of a command when printing help or generating docs
DisableFlagsInUseLine bool

// DisableArgsInUseLine will disable the addition of [args] to the usage
// line of a command when printing help or generating docs
DisableArgsInUseLine bool

// DisableSuggestions disables the suggestions based on Levenshtein distance
// that go along with 'unknown command' messages.
DisableSuggestions bool
Expand Down Expand Up @@ -1271,6 +1275,9 @@ func (c *Command) UseLine() string {
if c.HasAvailableFlags() && !strings.Contains(useline, "[flags]") {
useline += " [flags]"
}
if c.HasAvailableArgs() && !strings.Contains(useline, "[args]") && !c.DisableArgsInUseLine {
useline += " [args]"
}
return useline
}

Expand Down Expand Up @@ -1613,6 +1620,11 @@ func (c *Command) HasAvailableInheritedFlags() bool {
return c.InheritedFlags().HasAvailableFlags()
}

// HasAvailableArgs checks if the command has non-nil Args.
func (c *Command) HasAvailableArgs() bool {
return c.Args != nil
}

// Flag climbs up the command tree looking for matching flag.
func (c *Command) Flag(name string) (flag *flag.Flag) {
flag = c.Flags().Lookup(name)
Expand Down

0 comments on commit 1a75560

Please sign in to comment.