0

Suppose one has the following code:

#!/usr/bin/python
"""Does something.

Usage: 
   myprog.py --myopt=<myval>

Options:
  --myopt=<myval>  Some option [default: bla]
"""

arguments = docopt(__doc__)
print arguments

Is there a way to check whether the user gave a value for the option '--myopt', or left the default value unchanged?

I'd hate to repeat the default value in an if-statement like this:

if arguments['--myopt'] != 'bla':

or use a regex on __doc__ to extract the default value from the docstring. After all, docopt already did parse the docstring.

con-f-use
  • 3,772
  • 5
  • 39
  • 60

1 Answers1

0

Do you mean like this? This would print the doc help if the --myopt argument was not used or had a blank entry.

if arguments['--myopt'] is None: print __doc__ exit(0)

iNoob
  • 1,375
  • 3
  • 19
  • 47