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

feature: support more group flags #1936

Closed
YoniRomm opened this issue Mar 26, 2023 · 5 comments
Closed

feature: support more group flags #1936

YoniRomm opened this issue Mar 26, 2023 · 5 comments

Comments

@YoniRomm
Copy link

YoniRomm commented Mar 26, 2023

I had a use cases where I needed:

  1. I had 2 group of flags and I needed that one flag from each group will be presented (but together something like MarkFlagsRequiredTogether but between 2 groups)
  2. enforce the flag value to be from a list of options
  3. enforce exactly 1 flag to be presented from a group (similar to MarkFlagsMutuallyExclusive)
@YoniRomm YoniRomm changed the title feature: support more Group flags feature: support more group flags Mar 26, 2023
@marevers
Copy link
Contributor

marevers commented Apr 26, 2023

I recently opened a PR #1952 which should address point 3.

@marevers
Copy link
Contributor

marevers commented Jun 14, 2023

@YoniRomm My PR should actually address point 1 as well. You can create two flag groups and set MarkFlagsOneRequired and MarkFlagsMutuallyExclusive for both. This will enforce at least one flag and not more than one from each group.

The only thing not covered is 2, which, if I understand correctly is not about the flag itself (its name) but its value? I think there is no way to do that currently out-of-the-box, but you could also implement your own logic to check if the flag value comes from a list of expected options.

@gabguy
Copy link

gabguy commented Aug 8, 2023

@marevers MarkFlagsOneRequired function does not exist on the latest release (1.7.0).
It was added under commit c81c46a, but there is no tag that includes this addition.
Can you please create another release with this code in it?

@marevers
Copy link
Contributor

marevers commented Aug 8, 2023

@gabguy I am not a maintainer, so I cannot create releases. I do know, however, that the addition of MarkFlagsOneRequired is planned for the next release (1.8.0).

@marevers
Copy link
Contributor

marevers commented Feb 16, 2024

@YoniRomm @gabguy 1.8.0 was released which contains the feature: https://github.com/spf13/cobra/releases/tag/v1.8.0
So this can now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants