Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicting and Implied flags #1238

Closed
binaek opened this issue Sep 29, 2020 · 3 comments · Fixed by #1654
Closed

Conflicting and Implied flags #1238

binaek opened this issue Sep 29, 2020 · 3 comments · Fixed by #1654
Labels
area/flags-args Changes to functionality around command line flags and args kind/feature A feature request for cobra; new or enhanced behavior lifecycle/needs-proposal For large features/bugs that need a proposal and community buy in

Comments

@binaek
Copy link

binaek commented Sep 29, 2020

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?

@github-actions
Copy link

This issue is being marked as stale due to a long period of inactivity

@edmondop
Copy link

edmondop commented Feb 23, 2022

This cases cause a lot of boilerplate

@johnSchnake
Copy link
Collaborator

I agree there are some opportunities for flags that are more...context-aware?

There are a few different issues around things like this and I think the use cases are significant enough to investigate further. It does cause a lot of annoying code to do some of these basic flag checks.

@johnSchnake johnSchnake added area/flags-args Changes to functionality around command line flags and args kind/feature A feature request for cobra; new or enhanced behavior lifecycle/needs-proposal For large features/bugs that need a proposal and community buy in and removed kind/stale labels Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flags-args Changes to functionality around command line flags and args kind/feature A feature request for cobra; new or enhanced behavior lifecycle/needs-proposal For large features/bugs that need a proposal and community buy in
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants