docopt / docopt.c

C-code generator for docopt language.
MIT License
318 stars 46 forks source link

arguments not working #32

Open acornejo opened 9 years ago

acornejo commented 9 years ago

I tried docopt.c for the first time today.

Running the example doesn't work, for example, see the following output:

$ ./example ship test move 4 5 --speed=20
Commands
    mine == false
    move == true
    create == false
    remove == false
    set == false
    ship == true
    shoot == false
Arguments
    x == (null)
    y == (null)
Flags
    --drifting == false
    --help == false
    --moored == false
    --version == false
Options
    --speed == 20

As you can see, the move command and the --speed option were read correctly, but the <x> and <y> arguments were NOT populated.

noisygecko commented 9 years ago

I noticed that same problem.

OzgurEraslan commented 9 years ago

As stated in README.md, only options are supported at the moment.

and are positional arguments. README.md: > Note, at this point the code generator handles only options (positional arguments, commands and pattern matching will follow).
jkcko commented 6 years ago

Example of program execution in my fork. Of course, my python experience is lacking so it's probably not the cleanest solution. My fork also support options before or after positional arguments.

$ ./example -h
Naval Fate.

Usage:
  naval_fate.py ship create <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 anchor [--up] [<number>]
  naval_fate.py --help
  naval_fate.py --version

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

$ ./example ship test move 4 5 --speed=20
Commands
    mine == false
    move == true
    create == false
    remove == false
    set == false
    ship == true
    shoot == false
    anchor == false
Arguments
    name == test
    x == 4
    y == 5
    number == (null)
Flags
    --drifting == false
    --help == false
    --moored == false
    --up == false
    --version == false
Options
    --speed == 20