cobra icon indicating copy to clipboard operation
cobra copied to clipboard

Mark flag mutually exclusive and required

Open shanduur-auto opened this issue 2 years ago • 1 comments

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]

shanduur-auto avatar Jul 22 '22 12:07 shanduur-auto

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.

marckhouzam avatar Jul 23 '22 14:07 marckhouzam

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

github-actions[bot] avatar Sep 22 '22 00:09 github-actions[bot]

Fixed by @marevers in #1952

marckhouzam avatar Jul 16 '23 20:07 marckhouzam