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

How to define mutually exlusive flags #1358

Open
fangxlmr opened this issue Mar 1, 2021 · 4 comments
Open

How to define mutually exlusive flags #1358

fangxlmr opened this issue Mar 1, 2021 · 4 comments
Labels
area/flags-args Changes to functionality around command line flags and args kind/feature A feature request for cobra; new or enhanced behavior

Comments

@fangxlmr
Copy link

fangxlmr commented Mar 1, 2021

Say, I've got flag -x/--enable-x, and -X/--disable-x which disable the effect of previous -x/--enable-x option. Surely, it's easy to enable either one of them in the logic silently. But it'd be interesting to see any mutually exlusive definition which will directly exit when encounter both -x and -X flags, and warn user about this.

I couldn't find any docs related in cobra and pflag.

@cupcakearmy
Copy link

Also interested in this.

@github-actions
Copy link

github-actions bot commented Jun 8, 2021

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

@cupcakearmy
Copy link

But still relevant dear bot ❤️

@johnSchnake
Copy link
Collaborator

I think in this case there are two issues:

  • how to get that basic functionality of -x vs -X. Thats pretty simple to do since you can just create two flags with the same backing boolean value.
  • how can you get warnings or errors if both are set? This is more manual to accomplish and would require visiting the flags. I've had situations similar to this where I provide warnings if certain flags are provided together. I do think that there is something that could be done to improve that experience.

@johnSchnake johnSchnake added kind/feature A feature request for cobra; new or enhanced behavior area/flags-args Changes to functionality around command line flags and args and removed kind/stale labels Mar 23, 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
Projects
None yet
Development

No branches or pull requests

3 participants