Skip to content

Commit 7d85dc4

Browse files
author
Vladimir Keleshev
committed
Merge pull request #27 from tjeezy/fix_default_options
fixes default option value (closes issue #26)
2 parents 08c5236 + a420978 commit 7d85dc4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

docopt.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ int elems_to_args(Elements *elements, DocoptArgs *args, bool help,
286286
} else if (!strcmp(option->olong, "--version")) {
287287
args->version = option->value;
288288
} else if (!strcmp(option->olong, "--speed")) {
289-
args->speed = option->argument;
289+
if (option->argument)
290+
args->speed = option->argument;
290291
}
291292
}
292293
/* commands */
@@ -363,3 +364,4 @@ DocoptArgs docopt(int argc, char *argv[], bool help, const char *version) {
363364
exit(EXIT_SUCCESS);
364365
return args;
365366
}
367+

docopt_c.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def c_if_flag(o):
9191

9292
def c_if_option(o):
9393
t = """ else if (!strcmp(option->o%s, %s)) {
94-
args->%s = option->argument;
94+
if (option->argument)
95+
args->%s = option->argument;
9596
}"""
9697
return t % (('long' if o.long else 'short'),
9798
to_c(o.long or o.short),

0 commit comments

Comments
 (0)