Search code examples
pythondocopt

With Python Docopt, how can I have "one parameter or more required"?


I have something like this at this moment.

Usage:
    main.py start without ([--db] [--faced] [--ird]) [--save]

What I want is for start without to have at least one or more parameters of --db, --faced, and/or --ird.

The --save will be an optional parameter.

So python3 -B main.py start without will not work and python3 -B main.py start without --save will also not work.

How can I achieve that?


Solution

  • Currently my best solution.

    Usage:
        main.py start without ((--db) [--faced] [--ird]) [--save]
        main.py start without ([--db] (--faced) [--ird]) [--save]
        main.py start without ([--db] [--faced] (--ird)) [--save]
    

    I found better solution from /u/ingolemo in my Reddit thread, https://www.reddit.com/r/learnpython/comments/5l3k2m/with_python_docopt_how_can_i_have_one_parameter/

    main.py start without (--db|--faced|--ird)... [--save]