summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2009-03-08 19:15:08 +0100
committerJunio C Hamano <gitster@pobox.com>2009-03-08 13:36:27 -0700
commitb92891f9783ae197bb84b90d8404ad08c3875fa1 (patch)
tree780f9dc1cd6d4dbf7a8b8f524c054ce9cf0ec7da /parse-options.c
parentb5ce3a54302cb6e29a02cd8fe4ea55eacea0a86e (diff)
downloadgit-b92891f9783ae197bb84b90d8404ad08c3875fa1.tar.gz
parseopt: add PARSE_OPT_NO_INTERNAL_HELP
Add a parseopt flag, PARSE_OPT_NO_INTERNAL_HELP, that turns off internal handling of -h, --help and --help-all. This allows the implementation of custom help option handlers or incremental parsers. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/parse-options.c b/parse-options.c
index 39808ae458..8b21dea72e 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -253,6 +253,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
const struct option *options,
const char * const usagestr[])
{
+ int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
+
/* we must reset ->opt, unknown short option leave it dangling */
ctx->opt = NULL;
@@ -268,7 +270,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
if (arg[1] != '-') {
ctx->opt = arg + 1;
- if (*ctx->opt == 'h')
+ if (internal_help && *ctx->opt == 'h')
return parse_options_usage(usagestr, options);
switch (parse_short_opt(ctx, options)) {
case -1:
@@ -279,7 +281,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
if (ctx->opt)
check_typos(arg + 1, options);
while (ctx->opt) {
- if (*ctx->opt == 'h')
+ if (internal_help && *ctx->opt == 'h')
return parse_options_usage(usagestr, options);
switch (parse_short_opt(ctx, options)) {
case -1:
@@ -306,9 +308,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
break;
}
- if (!strcmp(arg + 2, "help-all"))
+ if (internal_help && !strcmp(arg + 2, "help-all"))
return usage_with_options_internal(usagestr, options, 1);
- if (!strcmp(arg + 2, "help"))
+ if (internal_help && !strcmp(arg + 2, "help"))
return parse_options_usage(usagestr, options);
switch (parse_long_opt(ctx, arg + 2, options)) {
case -1: