0

I am creating a cli with docopt and have the following issue (I'll bring in examples from their naval_fate example cli)

naval-fate --version or naval-fate -v will return the cli version but when try doing let's say naval-fate ship -v for a different purpose, it automatically returns the same result as the first two commands.

Is there a way to prevent docopt from doing this?

Thanks

Narine Cholakian
  • 189
  • 1
  • 2
  • 13

1 Answers1

0

You can prevent docopt from parsing -v as a special option by simply mention it yourself in the docstring, as an option. For example, suppose you would like to use -v for verbosity:

!/usr/bin/python
"""
Usage: ./ [options]

Options:
-v  show verbose printing
"""
from docopt import docopt

arguments = docopt(__doc__)
if arguments["-v"] == True:
    print "A verbose message"

In this case, running the script with no parameters will do nothing, while running it with -v will generate the string "A verbose message"

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