2

I want my program to require at least one argument from a set in order for the arguments to be valid.

So for the sake of example, let's say I have 3 switches (-a, -b and -c) and two mandatory arguments.

These would be valid. myapp -a FOO BAR myapp -a -b FOO BAR myapp -a -c FOO BAR

This would not be:

myapp FOO BAR

Jake
  • 1,701
  • 3
  • 23
  • 44

1 Answers1

1

You could use ellipsis ... to state that an option should appear one or more times:

Usage:
    myapp (-a|-b|-c)... <FOO> <BAR>

Here we state that either -a, -b, or -c should appear one or more times.

Accepts:

myapp -a FOO BAR
myapp -a -b FOO BAR
myapp -a -c FOO BAR

Rejects:

myapp FOO BAR
J. P. Petersen
  • 4,871
  • 4
  • 33
  • 33
  • Wouldn't that allow the flags to be provided multiple times though? i.e. `myapp -a -a -b`. Not that it's a problem, it's just an observation. – Jake May 15 '17 at 19:18
  • Yes, that is true. If you want to avoid that, then you probably have to spell out all the combinations, and that would make the command line specification less user friendly. So it is kind of a tradeoff. – J. P. Petersen May 16 '17 at 07:39
  • I can live with that. – Jake May 16 '17 at 13:17