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

Flags mutually exclusive but one of them required #1891

Closed
krystian-panek-vmltech opened this issue Jan 9, 2023 · 4 comments
Closed

Flags mutually exclusive but one of them required #1891

krystian-panek-vmltech opened this issue Jan 9, 2023 · 4 comments

Comments

@krystian-panek-vmltech
Copy link

krystian-panek-vmltech commented Jan 9, 2023

hey, thanks for cool library, I have only a one question:

func pkgDefineFileAndUrlFlags(cmd *cobra.Command) {
	cmd.Flags().String("file", "", "Local ZIP path")
	cmd.Flags().String("url", "", "URL to ZIP")
	cmd.MarkFlagsMutuallyExclusive("file", "url")
}

how to make only one of flags defined required, I mean --file or --url ? but not at the same time?

I see that there is MarkFlagsRequiredTogether but I more want to have sth like MarkFlagsRequiredSome("file", "url") :)

Any ideas have to handle such case?
Greetings, Krystian

@marckhouzam
Copy link
Collaborator

Sadly this is not supported. See #1761 .
You would have to implement that logic yourself in your program once the flags are parsed.

@krystian-panek-vmltech
Copy link
Author

ok, thanks for confirmation; I hope I will find some time to improve it in Cobra someday :)

@marckhouzam
Copy link
Collaborator

ok, thanks for confirmation; I hope I will find some time to improve it in Cobra someday :)

That would be great!

@marckhouzam
Copy link
Collaborator

Fixed by @marevers in #1952

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

2 participants