parse-options: clearer reporting of API misuse
[git.git] / parse-options.c
index 9bbbc6a5fec7fa3500fe5d830a188717d70ad0c5..67d1adca0a13b550c930d8cc7a95bd2b53a4332f 100644 (file)
@@ -11,6 +11,13 @@ static int parse_options_usage(struct parse_opt_ctx_t *ctx,
 #define OPT_SHORT 1
 #define OPT_UNSET 2
 
+static int optbug(const struct option *opt, const char *reason)
+{
+       if (opt->long_name)
+               return error("BUG: option '%s' %s", opt->long_name, reason);
+       return error("BUG: switch '%c' %s", opt->short_name, reason);
+}
+
 static int opterror(const struct option *opt, const char *reason, int flags)
 {
        if (flags & OPT_SHORT)
@@ -320,20 +327,12 @@ static void parse_options_check(const struct option *opts)
 
        for (; opts->type != OPTION_END; opts++) {
                if ((opts->flags & PARSE_OPT_LASTARG_DEFAULT) &&
-                   (opts->flags & PARSE_OPT_OPTARG)) {
-                       if (opts->long_name) {
-                               error("`--%s` uses incompatible flags "
-                                     "LASTARG_DEFAULT and OPTARG", opts->long_name);
-                       } else {
-                               error("`-%c` uses incompatible flags "
-                                     "LASTARG_DEFAULT and OPTARG", opts->short_name);
-                       }
-                       err |= 1;
-               }
+                   (opts->flags & PARSE_OPT_OPTARG))
+                       err |= optbug(opts, "uses incompatible flags "
+                                       "LASTARG_DEFAULT and OPTARG");
        }
-
        if (err)
-               exit(129);
+               exit(128);
 }
 
 void parse_options_start(struct parse_opt_ctx_t *ctx,