summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/parse-options.c b/parse-options.c
index f7ce523a61..d218122af5 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -3,6 +3,9 @@
#include "cache.h"
#include "commit.h"
+static int parse_options_usage(const char * const *usagestr,
+ const struct option *opts);
+
#define OPT_SHORT 1
#define OPT_UNSET 2
@@ -230,6 +233,9 @@ is_abbreviated:
abbrev_flags = flags;
continue;
}
+ /* negation allowed? */
+ if (options->flags & PARSE_OPT_NONEG)
+ continue;
/* negated and abbreviated very much? */
if (!prefixcmp("no-", arg)) {
flags |= OPT_UNSET;
@@ -511,7 +517,7 @@ static int usage_with_options_internal(const char * const *usagestr,
continue;
pos = fprintf(stderr, " ");
- if (opts->short_name) {
+ if (opts->short_name && !(opts->flags & PARSE_OPT_NEGHELP)) {
if (opts->flags & PARSE_OPT_NODASH)
pos += fprintf(stderr, "%c", opts->short_name);
else
@@ -520,7 +526,9 @@ static int usage_with_options_internal(const char * const *usagestr,
if (opts->long_name && opts->short_name)
pos += fprintf(stderr, ", ");
if (opts->long_name)
- pos += fprintf(stderr, "--%s", opts->long_name);
+ pos += fprintf(stderr, "--%s%s",
+ (opts->flags & PARSE_OPT_NEGHELP) ? "no-" : "",
+ opts->long_name);
if (opts->type == OPTION_NUMBER)
pos += fprintf(stderr, "-NUM");
@@ -547,8 +555,16 @@ void usage_with_options(const char * const *usagestr,
exit(129);
}
-int parse_options_usage(const char * const *usagestr,
- const struct option *opts)
+void usage_msg_opt(const char *msg,
+ const char * const *usagestr,
+ const struct option *options)
+{
+ fprintf(stderr, "%s\n\n", msg);
+ usage_with_options(usagestr, options);
+}
+
+static int parse_options_usage(const char * const *usagestr,
+ const struct option *opts)
{
return usage_with_options_internal(usagestr, opts, 0);
}
@@ -620,3 +636,10 @@ int parse_opt_with_commit(const struct option *opt, const char *arg, int unset)
commit_list_insert(commit, opt->value);
return 0;
}
+
+int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
+{
+ int *target = opt->value;
+ *target = unset ? 2 : 1;
+ return 0;
+}