python - How to prevent docopt from swallowing an option? -


i'm trying create command-line interface using docopt. here simplified version of file:

#!/usr/bin/env python """ test program.  usage:   test.py [options]  options:   -a <input>       -b   -c   -d """ import docopt  print docopt.docopt(__doc__) 

i want able specify of options, in order. however, if forget specify argument -a flag, output this:

$ python test.py -a -b -c {"-a": "-b",  "-b": false,  "-c": true,  "-d": false} 

docopt treating -b flag argument -a flag, instead of rejecting input invalid. there easy way detect this, or make docopt refuse accept sort of malformed input?

there ambiguities concerning short option : better use --option=arg long option :

-o --option

words starting 1 or 2 dashes (with exception of "-", "--" themselves) interpreted short (one-letter) or long options, respectively.

- short options can "stacked" meaning -abc equivalent -a -b -c. - long options can have arguments specified after space or equal "=" sign: --input=arg equivalent --input arg. -short options can have arguments specified after optional space: -f file equivalent -ffile. 

note, writing --input arg (opposed --input=arg) ambiguous, meaning not possibe tell whether arg option's argument or positional argument. in usage patterns interpreted option argument if option's description (covered below) option provided. otherwise interpreted separate option , positional argument.

same ambiguity -f file , -ffile notation. although in latter case not possible tell whether number of stacked short options, or option argument. these notations interpreted option argument if option's description provided.


Comments