0

I have three arguments: --a --b --c and I want my command to accept at least on of them but all combinations of a/b/c are also valid. E.g:

command.py --a
command.py --a --b
command.py --a --b --c
...

but not without arguments:

command.py

Thanks!

Bruce
  • 1,380
  • 2
  • 13
  • 17

1 Answers1

1

I want my command to accept at least on of them

You can do the following:

>>> from docopt import docopt
>>> u = '''usage: command.py --a [--b --c]
...               command.py --b [--a --c]
...               command.py --c [--a --b]'''
>>> docopt(u, ['--a'])
{'--a': True,
 '--b': False,
 '--c': False}
>>> docopt(u, ['--b'])
{'--a': False,
 '--b': True,
 '--c': False}
>>> docopt(u, ['--c'])
{'--a': False,
 '--b': False,
 '--c': True}
>>> docopt(u, [])
usage: command.py --a [--b --c]
       command.py --b [--a --c]
       command.py --c [--a --b]

Although this might not be the most user-friendly command-line interface. Maybe, you could explain your interface in more detail, and I can advise you on how to implement it (possibly with not only options, but also commands and positional arguments).

Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93