Skip to content

Commit

Permalink
Merge pull request #27 from tjeezy/fix_default_options
Browse files Browse the repository at this point in the history
fixes default option value (closes issue #26)
  • Loading branch information
Vladimir Keleshev committed Mar 10, 2014
2 parents 08c5236 + a420978 commit 7d85dc4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -363,3 +364,4 @@ DocoptArgs docopt(int argc, char *argv[], bool help, const char *version) {
exit(EXIT_SUCCESS);
return args;
}

3 changes: 2 additions & 1 deletion docopt_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 7d85dc4

Please sign in to comment.