I'm trying to frame a docopt usage which accepts set of options.
Naval Fate.
Usage:
naval_fate.py ship
[-b <b_command>]
[-e <e_command>]
If I use this, it works fine:
ship -b barg -e earg
The output is:
{
"-b": true,
"-e": true,
"<b_command>": "barg",
"<e_command>": "earg",
"ship": true
}
But if use this, it still gives the same values to the respective arguments:
ship -e earg -b barg
Output:
{
"-b": true,
"-e": true,
"<b_command>": "earg",
"<e_command>": "barg",
"ship": true
}
Note that I passed earg to -e but it is assigned to b_command in the output.
I saw the same behavior with golang's docopt-go
package. Is my usage string wrong? If so, how should I frame the docopt usage string such that it assigns the correct values correct arguments and honors the specified arguments?
naval_fate.py ship [-b <b_command>] [-e <e_command>]
The interpretation of the docopt you wrote is as follows:
ship
,-b
,<b_command>
,-e
,<e_command>
.So all of the following would be considered legal input commands:
naval_fate.py ship -e
naval_fate.py ship BB -e
naval_fate.py ship -eb
naval_fate.py ship BB EE
The correct way to express flags like -b <b_command>
and -e <e_command>
is through a section called Options
.
Naval Fate.
Usage:
naval_fate.py ship [options]
Options:
-b <b_command> Description of -b
-e <e_command> Description of -e