0

I am having a problem with my usage statements in docopt.

This is how I'd expect usage to work in the script. The optional parameters (defined with []), I would like to be able to use them together or individually. So -t -o or -o or -t should be valid. At the moments I cant use -o without -t. If i use pipe | to separate them I can't use both at the same time. I've tried various combinations. I cant seem to get it work as id like. Can anyone point out where I am going wrong?

"""
Description:

Script does stuff

Usage:
  script.py (-d <ditem>) (-u <uitem>) (-p <pitem>) (-s <sfile>) [-t <tfile>] [-o <ofile>] [-v]
  script.py (-d <ditem>) (-l) [-t <tfile>] [-o <ofile>] [-v]
  script.py -h | --help
  script.py --version

Options:
  -v --verbose       Does stuff
  -t --tfile         Does stuff
  -o --output        Does stuff
  -l --litem         Does stuff
  -u --uitem         Does stuff
  -p --pitem         Does stuff
  -d --ditem         Does stuff
  -s --sitem         Does stuff
  -h --help          Show this screen.
  --version          Show version.
  """
Cœur
  • 37,241
  • 25
  • 195
  • 267
iNoob
  • 1,375
  • 3
  • 19
  • 47

2 Answers2

0

I was able to resolve this by using the following:

By adding the usage strings script.py (-d <ditem>) (-l) ([-t <tfile>] | [-o <ofile>]) [-v] and another script.py (-d <ditem>) (-l) [-t <tfile>] [-o <ofile>] [-v] means I can use -t and -o independently or -t -o together. However Im not able to use them in this order -o -t.

Description:

Script does stuff

Usage:
  script.py (-d <ditem>) (-u <uitem>) (-p <pitem>) (-s <sfile>) [-t <tfile>] [-o <ofile>] [-v]
  script.py (-d <ditem>) (-l) ([-t <tfile>] | [-o <ofile>]) [-v]
  script.py (-d <ditem>) (-l) [-t <tfile>] [-o <ofile>] [-v]
  script.py -h | --help
  script.py --version
iNoob
  • 1,375
  • 3
  • 19
  • 47
0

To allow -t along, -o along, -t and -o together:

Script does stuff.

Usage:
   script.py [-t] [-o] 

Options:
  -t --tfile         Does stuff
  -o --output        Does stuff

If it is an error when both -t and -o are absent:

Script does stuff.

Usage:
   script.py -t
   script.py -o
   script.py -t -o

Options:
  -t --tfile         Does stuff
  -o --output        Does stuff
jfs
  • 399,953
  • 195
  • 994
  • 1,670
  • ive resolved this already thank you. My answer above fixes it but I cant accept my answer as an answer unfortunately – iNoob Apr 01 '14 at 17:05
  • @iNoob: [your answer](http://stackoverflow.com/a/22787398/4279) contains contradictory usage e.g., `(a | b)` on one line and just `a b` on another. – jfs Apr 01 '14 at 17:11