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.info>
  • Loading branch information
danmx committed Aug 27, 2020
1 parent 02a0d2f commit f2d156e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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 @@ -1233,12 +1237,12 @@ func (c *Command) UseLine() string {
} else {
useline = c.Use
}
if c.DisableFlagsInUseLine {
return useline
}
if c.HasAvailableFlags() && !strings.Contains(useline, "[flags]") {
if c.HasAvailableFlags() && !strings.Contains(useline, "[flags]") && !c.DisableFlagsInUseLine {
useline += " [flags]"
}
if c.HasAvailableArgs() && !strings.Contains(useline, "[args]") && !c.DisableArgsInUseLine {
useline += " [args]"
}
return useline
}

Expand Down Expand Up @@ -1581,6 +1585,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 f2d156e

Please sign in to comment.