Code

i18n: git-clean clean.requireForce messages
[git.git] / parse-options.c
index 79c56f32f92acc2dc28694f8d8bbcd0b59c3ebba..42b51ef14514f3c3df454e4b718718a9b58f1612 100644 (file)
@@ -62,25 +62,13 @@ static int get_value(struct parse_opt_ctx_t *p,
                return opterror(opt, "takes no value", flags);
        if (unset && (opt->flags & PARSE_OPT_NONEG))
                return opterror(opt, "isn't available", flags);
-
-       if (!(flags & OPT_SHORT) && p->opt) {
-               switch (opt->type) {
-               case OPTION_CALLBACK:
-                       if (!(opt->flags & PARSE_OPT_NOARG))
-                               break;
-                       /* FALLTHROUGH */
-               case OPTION_BOOLEAN:
-               case OPTION_BIT:
-               case OPTION_NEGBIT:
-               case OPTION_SET_INT:
-               case OPTION_SET_PTR:
-                       return opterror(opt, "takes no value", flags);
-               default:
-                       break;
-               }
-       }
+       if (!(flags & OPT_SHORT) && p->opt && (opt->flags & PARSE_OPT_NOARG))
+               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;
@@ -385,7 +373,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
                        if (parse_nodash_opt(ctx, arg, options) == 0)
                                continue;
                        if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
-                               break;
+                               return PARSE_OPT_NON_OPTION;
                        ctx->out[ctx->cpidx++] = ctx->argv[0];
                        continue;
                }
@@ -467,6 +455,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
        switch (parse_options_step(&ctx, options, usagestr)) {
        case PARSE_OPT_HELP:
                exit(129);
+       case PARSE_OPT_NON_OPTION:
        case PARSE_OPT_DONE:
                break;
        default: /* PARSE_OPT_UNKNOWN */
@@ -552,7 +541,8 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
                if (opts->type == OPTION_NUMBER)
                        pos += fprintf(outfile, "-NUM");
 
-               if (!(opts->flags & PARSE_OPT_NOARG))
+               if ((opts->flags & PARSE_OPT_LITERAL_ARGHELP) ||
+                   !(opts->flags & PARSE_OPT_NOARG))
                        pos += usage_argh(opts, outfile);
 
                if (pos <= USAGE_OPTS_WIDTH)