Skip to content

Conflicting and Implied flags #1238

@binaek

Description

@binaek

Is there a way to set conflicting and implied flags in cobra?

conflicting
When I am allowing the user to set some output mode to json/csv, I would have two flags (as opposed to --output json|csv just to make the users' life easier)

  • --json
  • --csv

However, setting these two flags together like exampleCmd subCmd --json --csv does not make sense and hence needs to be blocked.

implied
At the same time, there are flags which may have to be used together to make sense (implied flags).

Example:= a credentials combo (username/password or apikey/apisecret)

Using one without the other does not make sense.

Ofcourse we could have custom logic in the handlers to take care of this, but that would mean repetition on every handler (even if it's a simple function call).

Does cobra support these in some way?

If not, is this a planned feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/flags-argsChanges to functionality around command line flags and argskind/featureA feature request for cobra; new or enhanced behaviorlifecycle/needs-proposalFor large features/bugs that need a proposal and community buy in

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions