spf13/cobra

Can there be support for "Parameter sets" if there isn't already?

red8888 opened this issue · 1 comments

I'd like to be able to define various dependent flags relative to each other.

To describe behaviour like:

  • Either flagX OR flagY must be supplied
  • Mutual exclusivity like if flagX supplied flagY cannot be supplied
  • Grouping required params like if flagX is supplied then flagY must also be supplied

But I want to do this declaratively in a terse readable way.

Powershell has supported this for like a decade with "Parameter Sets" which make this trivial: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parameter_sets?view=powershell-7.3.

In PS this is of course built into the language itself, but could anything like this ever be supported in cobra so I don't have to roll a bunch of custom logic? For example maybe just some builtin cmd.ParameterSet() method that can be used to group PersistentFlags()/Flags() into parameter sets?

Sorry I didn't see this, looks like this is semi supported already #1952