cobra
cobra copied to clipboard
Add '[args]' and 'Valid Args:' to --help
Close #571 and Close #576.
This PR is based on #841, and it must be merged after that. See difference: https://github.com/umarcor/cobra/compare/feat-matchvalid...umarcor:feat-validinhelp
The added feature is to modify the output of Usage()
to print [args]
if the command accepts args:
Usage:
app [args] # instead of 'app'
app [flags] [args] # instead of 'app [flags]'
app [command]
Valid Args:
one two three
-
app [args]
andapp [flags] [args]
are not shown at the same time. -
[args]
is only added if the command is runnable, andArgs != NoArgs
, orArgs == nil && (!c.HasAvailableSubCommands() || c.HasParent())
, etc. -
Valid Args
is only shown ifValidArgs
is not empty and[args]
is shown.
To Do
- As suggested in #571:
- [ ] When
MinimumNArgs
,ExactArgs
orRangeArgs
are used,args
should be shown instead of[args]
. - [ ] The
Usage()
should show the constraints applied to the args (NArgs>x
,NArgs<x
,NArgs=x
orx<NArgs<y
).
- [ ] When
These have not been implemented yet, because I don't know any easy mechanism to detect the type of c.Args
.
- [ ] As commented in #841: tests could be greatly improved by implementing them as sub-tests and grouping them per validation function.
- [ ] As suggested in #841, we should properly handle different sources of errors, instead of relying on comparing strings. See https://github.com/pkg/errors and https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
Ref #666, Ref #635 and Ref #706.
This is still WIP, but it depends on #841 being merged.
This PR is being marked as stale due to a long period of inactivity
This PR is not stale, but blocked by #841. Please, remove the kind/stale
label.
See https://github.com/spf13/cobra/issues/1496#issuecomment-989131001 and https://github.com/spf13/cobra/issues/1496#issuecomment-989287359.
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.