Skip to content

Commit fc97c0c

Browse files
committed
feat(command): adding args to use line
Signed-off-by: danmx <[email protected]>
1 parent 0c72800 commit fc97c0c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

command.go

+12
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ type Command struct {
240240
// line of a command when printing help or generating docs
241241
DisableFlagsInUseLine bool
242242

243+
// DisableArgsInUseLine will disable the addition of [args] to the usage
244+
// line of a command when printing help or generating docs
245+
DisableArgsInUseLine bool
246+
243247
// DisableSuggestions disables the suggestions based on Levenshtein distance
244248
// that go along with 'unknown command' messages.
245249
DisableSuggestions bool
@@ -1419,6 +1423,9 @@ func (c *Command) UseLine() string {
14191423
if c.HasAvailableFlags() && !strings.Contains(useline, "[flags]") {
14201424
useline += " [flags]"
14211425
}
1426+
if c.HasAvailableArgs() && !strings.Contains(useline, "[args]") && !c.DisableArgsInUseLine {
1427+
useline += " [args]"
1428+
}
14221429
return useline
14231430
}
14241431

@@ -1762,6 +1769,11 @@ func (c *Command) HasAvailableInheritedFlags() bool {
17621769
return c.InheritedFlags().HasAvailableFlags()
17631770
}
17641771

1772+
// HasAvailableArgs checks if the command has non-nil Args.
1773+
func (c *Command) HasAvailableArgs() bool {
1774+
return c.Args != nil
1775+
}
1776+
17651777
// Flag climbs up the command tree looking for matching flag.
17661778
func (c *Command) Flag(name string) (flag *flag.Flag) {
17671779
flag = c.Flags().Lookup(name)

0 commit comments

Comments
 (0)