Use setup_work_tree() in builtin-ls-files.c
[gitweb.git] / parse-options.c
index b4a3b63e9f33b9f2af40fd8cf17dd2aeff312a35..cc09c98ec3fe19d6f9f5f7a58a3c5956bd7c0578 100644 (file)
@@ -72,6 +72,11 @@ static int get_value(struct optparse_t *p,
        case OPTION_CALLBACK:
                if (flags & OPT_UNSET)
                        return (*opt->callback)(opt, NULL, 1);
+               if (opt->flags & PARSE_OPT_NOARG) {
+                       if (p->opt && !(flags & OPT_SHORT))
+                               return opterror(opt, "takes no value", flags);
+                       return (*opt->callback)(opt, NULL, 0);
+               }
                if (opt->flags & PARSE_OPT_OPTARG && (!arg || *arg == '-'))
                        return (*opt->callback)(opt, NULL, 0);
                if (!arg)
@@ -261,8 +266,11 @@ void usage_with_options(const char * const *usagestr,
                        else
                                pos += fprintf(stderr, " <n>");
                        break;
-               case OPTION_STRING:
                case OPTION_CALLBACK:
+                       if (opts->flags & PARSE_OPT_NOARG)
+                               break;
+                       /* FALLTHROUGH */
+               case OPTION_STRING:
                        if (opts->argh) {
                                if (opts->flags & PARSE_OPT_OPTARG)
                                        pos += fprintf(stderr, " [<%s>]", opts->argh);