docopt / DocOpt.jl

command line arguments parser
Other
90 stars 21 forks source link

Does not correctly handle multi-line option descriptions #18

Open staticfloat opened 7 years ago

staticfloat commented 7 years ago

If I have a multi-line option description, DocOpt.jl does not correctly group all lines together, it merely grabs the first line, discarding the rest due to this filter!() call removing all lines that do not start with - after strip()'ing. This stops option descriptions such as the following from working properly:

Naval Fate.

Usage:
  naval_fate.py ship new <name>...
  naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.py ship shoot <x> <y>
  naval_fate.py mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.py -h | --help
  naval_fate.py --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots
                Has a default value [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

This is identical to the canonical docopt example except that the --speed option spans multiple lines. When trying it out on try.docopt.org, you can see that --speed is correctly defaulted to 10. However, when running with Julia using this file:

doc = """Naval Fate.

Usage:
  naval_fate.py ship new <name>...
  naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.py ship shoot <x> <y>
  naval_fate.py mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.py -h | --help
  naval_fate.py --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots
                Has a default value [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.
"""
using DocOpt

arguments = docopt(doc)
for key in keys(arguments)
    println("* $(key): $(arguments[key])")
end

It does not print out the default value properly:

$ julia docopt_test.jl ship Guardian move 10 50
* remove: false
* --help: false
* <name>: String["Guardian"]
* --drifting: false
* mine: false
* move: true
* --version: false
* --moored: false
* <x>: 10
* ship: true
* new: false
* shoot: false
* set: false
* <y>: 50
* --speed: nothing
bicycle1885 commented 7 years ago

Thank you for reporting a problem. It seems to be a bug of DocOpt.jl. I'll take a look and fix it within a few days.