Note, at this point the code generator handles only options (positional arguments, commands and pattern matching will follow).
Naval Fate.
Usage:
naval_fate ship create <name>...
naval_fate ship <name> move <x> <y> [--speed=<kn>]
naval_fate ship shoot <x> <y>
naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
naval_fate --help
naval_fate --version
Options:
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.
$ python -m docopt_c -o docopt.c example.docopt
or by using pipe
$ cat example.docopt | python -m docopt_c > docopt.c
docopt.c
into your program#include "docopt.h"
int main(int argc, char *argv[])
{
struct DocoptArgs args = docopt(argc, argv, /* help */ 1, /* version */ "2.0rc2");
puts("Commands");
printf("\tmine == %s\n", args.mine ? "true" : "false");
printf("\tmove == %s\n", args.move ? "true" : "false");
printf("\tcreate == %s\n", args.create ? "true" : "false");
printf("\tremove == %s\n", args.remove ? "true" : "false");
printf("\tset == %s\n", args.set ? "true" : "false");
printf("\tship == %s\n", args.ship ? "true" : "false");
printf("\tshoot == %s\n", args.shoot ? "true" : "false");
puts("Arguments");
printf("\tx == %s\n", args.x);
printf("\ty == %s\n", args.y);
puts("Flags");
printf("\t--drifting == %s\n", args.drifting ? "true" : "false");
printf("\t--help == %s\n", args.help ? "true" : "false");
printf("\t--moored == %s\n", args.moored ? "true" : "false");
printf("\t--version == %s\n", args.version ? "true" : "false");
puts("Options");
printf("\t--speed == %s\n", args.speed);
return EXIT_SUCCESS;
}
$ c99 example.c -o example.out
$ ./example.out mine --drifting --speed=20
Commands
mine == true
move == false
create == false
remove == false
set == false
ship == false
shoot == false
Arguments
x == (null)
y == (null)
Flags
--drifting == true
--help == false
--moored == false
--version == false
Options
--speed == 20
See the Python version's page for more info on developing.