How to set only specific values for a parameter in docopt python?
<p>I am trying to use docopt for a python code. I actually need to set only specific values for a parameter. My usage is as below:</p>

<pre><code>"""
Usage:
test.py --list=(all|available)

Options:
    list    Choice to list devices (all / available)
"""
</code></pre>

<p>I've tried to run it as: <code>python test.py --list=all</code> but it doesn't accept the value and just displays the docopt string .</p>

<p>I want the value of list parameter to be either 'all' or 'available'. Is there any way this can be achieved?</p>

<p>Here's an example to achieve what you want:</p>

<p><strong>test.py:</strong></p>

<pre><code>"""
Usage:
  test.py list (all|available)

Options:
  -h --help     Show this screen.
  --version     Show version.

  list          Choice to list devices (all / available)
"""
from docopt import docopt

def list_devices(all_devices=True):
    if all_devices:
        print("Listing all devices...")
    else:
        print("Listing available devices...")


if __name__ == '__main__':
    arguments = docopt(__doc__, version='test 1.0')

    if arguments["list"]:
        list_devices(arguments["all"])
</code></pre>

<p>With this script you could run statements like:</p>

<pre><code>python test.py list all
</code></pre>

<p>or:</p>

<pre><code>python test.py list available 
</code></pre>

python docopt