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

Mark flag mutually exclusive and required #1761

Closed
shanduur-auto opened this issue Jul 22, 2022 · 3 comments
Closed

Mark flag mutually exclusive and required #1761

shanduur-auto opened this issue Jul 22, 2022 · 3 comments
Labels
area/flags-args Changes to functionality around command line flags and args

Comments

@shanduur-auto
Copy link

shanduur-auto commented Jul 22, 2022

Hi!

I want to ask, if there is an option to mark one of n of the mutually exclusive flags required? This means there must appear exactly one of the n flags, otherwise an error should be printed.

For example:

# this should print contents from file:
$ echo -f ./file.txt
hello world

# this should act as a regular echo:
$ echo -i "hello world"
hello world

# this should print help and info about missing required flags:
$ echo
Error: one of mutually exclusive required flag(s) not set: "f", "i"
Usage:
  echo [flags]
@marckhouzam marckhouzam added the area/flags-args Changes to functionality around command line flags and args label Jul 23, 2022
@marckhouzam
Copy link
Collaborator

Hi @shanduur-auto. Currently there is no special support from Cobra for what you are asking. You would have to do the verification yourself in your program.

@github-actions
Copy link

The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:

  • After 60d of inactivity, lifecycle/stale is applied. - After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied and the issue is closed.
    You can:
  • Make a comment to remove the stale label and show your support. The 60 days reset. - If an issue has lifecycle/rotten and is closed, comment and ask maintainers if they'd be interseted in reopening

@marckhouzam
Copy link
Collaborator

Fixed by @marevers in #1952

This issue was closed.
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
Projects
None yet
Development

No branches or pull requests

2 participants