summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-12-01 23:32:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-12-07 22:19:32 (GMT)
commitb0b3a8b666ac9bcab93c9b05ca7de918d7fa18bc (patch)
tree6f895828110cfc453744bde29f7f58ce3244b983 /parse-options.c
parentb57c68a69e028cc41eb01404dc4446a463c0e464 (diff)
downloadgit-b0b3a8b666ac9bcab93c9b05ca7de918d7fa18bc.zip
git-b0b3a8b666ac9bcab93c9b05ca7de918d7fa18bc.tar.gz
git-b0b3a8b666ac9bcab93c9b05ca7de918d7fa18bc.tar.bz2
parse-options: allow git commands to invent new option types
parse-options provides a variety of option behaviors, including OPTION_CALLBACK, which should take care of just about any sane behavior. All supported behaviors obey the following constraint: A --foo option can only accept (and base its behavior on) one argument, which would be the following command-line argument in the "unsticked" form. Alas, some existing git commands have options that do not obey that constraint. For example, update-index --cacheinfo takes three arguments, and update-index --resolve takes all later parameters as arguments. Introduces an OPTION_LOWLEVEL_CALLBACK backdoor to parse-options so such option types can be supported without tempting inventors of other commands through mention in the public API. Commands can set the callback field to a function accepting three arguments: the option parsing context, the option itself, and a flag indicating whether the the option was negated. When the option is encountered, that function is called to take over from get_value(). The return value should be zero for success, -1 for usage errors. Thanks to Stephen Boyd for API guidance. Improved-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/parse-options.c b/parse-options.c
index 632c134..cd92686 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -66,6 +66,9 @@ static int get_value(struct parse_opt_ctx_t *p,
return opterror(opt, "takes no value", flags);
switch (opt->type) {
+ case OPTION_LOWLEVEL_CALLBACK:
+ return (*(parse_opt_ll_cb *)opt->callback)(p, opt, unset);
+
case OPTION_BIT:
if (unset)
*(int *)opt->value &= ~opt->defval;