2

I usually use docopt to handle the command line parameters but I now have a case where the parameters is parsed unexpectedly (it must be a silly mistake of mine as it always works great)

"""
API to do something

Usage:
    api.py [options]

Options:
    --port PORT     port to listen on   [default: 64645]
    --url   URL     elasticsearch address   [default: http://elk.example.com:9200]
"""

This is parsed via a conf = docopt.docopt(__doc__) call after which I have conf set to

{
    '--port': '64645',
    '--url': False
}

The --url part is not correct but I cannot understand why.

WoJ
  • 27,165
  • 48
  • 180
  • 345

2 Answers2

4

It is because there are too many spaces between --url and URL, try:

"""
API to do something

Usage:
    api.py [options]

Options:
    --port PORT     port to listen on   [default: 64645]
    --url URL       elasticsearch address   [default: http://elk.example.com:9200]
"""
J. P. Petersen
  • 4,871
  • 4
  • 33
  • 33
0

Taken from official documentation:

To specify that an option has an argument, put a word describing that argument after one space or "=" sign.

Use two spaces to separate options with their informal description.

Community
  • 1
  • 1
Omer Dagan
  • 14,868
  • 16
  • 44
  • 60