diff --git a/docopt.c b/docopt.c index b032320..bb3392b 100644 --- a/docopt.c +++ b/docopt.c @@ -286,7 +286,8 @@ int elems_to_args(Elements *elements, DocoptArgs *args, bool help, } else if (!strcmp(option->olong, "--version")) { args->version = option->value; } else if (!strcmp(option->olong, "--speed")) { - args->speed = option->argument; + if (option->argument) + args->speed = option->argument; } } /* commands */ @@ -363,3 +364,4 @@ DocoptArgs docopt(int argc, char *argv[], bool help, const char *version) { exit(EXIT_SUCCESS); return args; } + diff --git a/docopt_c.py b/docopt_c.py index 0e288ee..e7b06fc 100644 --- a/docopt_c.py +++ b/docopt_c.py @@ -91,7 +91,8 @@ def c_if_flag(o): def c_if_option(o): t = """ else if (!strcmp(option->o%s, %s)) { - args->%s = option->argument; + if (option->argument) + args->%s = option->argument; }""" return t % (('long' if o.long else 'short'), to_c(o.long or o.short),