cobra
cobra copied to clipboard
Same flag in different groups that created by MarkFlagsRequiredTogether not work as expected
Hi all!
I would like to have different groups that created using option MarkFlagsRequiredTogether with the same flag. I.e. I would like to have this:
rootCmd.MarkFlagsRequiredTogether("cpuprofile","diag")
rootCmd.MarkFlagsRequiredTogether("memprofile", "diag")
to run memory or cpu profiling independently, like this:
--diag --memprofile
or
--diag --cpuprofile
or even altogether like this:
--diag --memprofile --cpuprofile
but independent run failed with
Error: if any flags in the group [cpuprofile diag] are set they must all be set; missing [cpuprofile]
Thanks for the report @aegoroff. Your usecase does makes sense to me, but the flag group feature does not support such a case 😞
If you specify MarkFlagsRequiredTogether()
then if any of the specified flags is present on the command-line, then all others must be present also.
Thank you for reply!
If you specify MarkFlagsRequiredTogether() then if any of the specified flags is present on the command-line, then all others must be present also.
Sure, so you cannot share an option among different groups. If so you have to use all options from all touched groups :(
It seems that MarkFlagsRequiredTogether call should create different groups that should be validated independently no matter a group option shared with another group or not
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
- After 60d of inactivity, lifecycle/stale is applied. - After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied and the issue is closed. You can:
- Make a comment to remove the stale label and show your support. The 60 days reset. - If an issue has lifecycle/rotten and is closed, comment and ask maintainers if they'd be interseted in reopening