summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b5ce3a5)
raw | patch | inline | side by side (parent: b5ce3a5)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Sun, 8 Mar 2009 18:15:08 +0000 (19:15 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 8 Mar 2009 20:36:27 +0000 (13:36 -0700) |
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>
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>
parse-options.c | patch | blob | history | |
parse-options.h | patch | blob | history |
diff --git a/parse-options.c b/parse-options.c
index 39808ae45850c7dc96f6288b969ba34be1556c39..8b21dea72e12416c806ae636e8a6f20f31ab9af8 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
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;
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:
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:
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:
diff --git a/parse-options.h b/parse-options.h
index b7d08b13d1493c0091f2431962a8bcb86ed035a8..f8ef1db1289f85e0877b66d4573044d962df934e 100644 (file)
--- a/parse-options.h
+++ b/parse-options.h
PARSE_OPT_STOP_AT_NON_OPTION = 2,
PARSE_OPT_KEEP_ARGV0 = 4,
PARSE_OPT_KEEP_UNKNOWN = 8,
+ PARSE_OPT_NO_INTERNAL_HELP = 16,
};
enum parse_opt_option_flags {