Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not correctly handle multi-line option descriptions #18

Open
staticfloat opened this issue Dec 15, 2016 · 1 comment
Open

Does not correctly handle multi-line option descriptions #18

staticfloat opened this issue Dec 15, 2016 · 1 comment

Comments

@staticfloat
Copy link
Collaborator

staticfloat commented Dec 15, 2016

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
@staticfloat staticfloat changed the title Does not handle multi-line option descriptions Does not correctly handle multi-line option descriptions Dec 15, 2016
@bicycle1885
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants