File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -240,6 +240,10 @@ type Command struct {
240
240
// line of a command when printing help or generating docs
241
241
DisableFlagsInUseLine bool
242
242
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
+
243
247
// DisableSuggestions disables the suggestions based on Levenshtein distance
244
248
// that go along with 'unknown command' messages.
245
249
DisableSuggestions bool
@@ -1419,6 +1423,9 @@ func (c *Command) UseLine() string {
1419
1423
if c .HasAvailableFlags () && ! strings .Contains (useline , "[flags]" ) {
1420
1424
useline += " [flags]"
1421
1425
}
1426
+ if c .HasAvailableArgs () && ! strings .Contains (useline , "[args]" ) && ! c .DisableArgsInUseLine {
1427
+ useline += " [args]"
1428
+ }
1422
1429
return useline
1423
1430
}
1424
1431
@@ -1762,6 +1769,11 @@ func (c *Command) HasAvailableInheritedFlags() bool {
1762
1769
return c .InheritedFlags ().HasAvailableFlags ()
1763
1770
}
1764
1771
1772
+ // HasAvailableArgs checks if the command has non-nil Args.
1773
+ func (c * Command ) HasAvailableArgs () bool {
1774
+ return c .Args != nil
1775
+ }
1776
+
1765
1777
// Flag climbs up the command tree looking for matching flag.
1766
1778
func (c * Command ) Flag (name string ) (flag * flag.Flag ) {
1767
1779
flag = c .Flags ().Lookup (name )
You can’t perform that action at this time.
0 commit comments