Merge branch 'fc/cherry-pick' into integration
[git] / parse-options.c
1 #include "git-compat-util.h"
2 #include "parse-options.h"
3 #include "cache.h"
4 #include "commit.h"
5 #include "color.h"
6 #include "utf8.h"
7
8 static int parse_options_usage(struct parse_opt_ctx_t *ctx,
9                                const char * const *usagestr,
10                                const struct option *opts, int err);
11
12 #define OPT_SHORT 1
13 #define OPT_UNSET 2
14
15 int optbug(const struct option *opt, const char *reason)
16 {
17         if (opt->long_name) {
18                 if (opt->short_name)
19                         return error("BUG: switch '%c' (--%s) %s",
20                                      opt->short_name, opt->long_name, reason);
21                 return error("BUG: option '%s' %s", opt->long_name, reason);
22         }
23         return error("BUG: switch '%c' %s", opt->short_name, reason);
24 }
25
26 int opterror(const struct option *opt, const char *reason, int flags)
27 {
28         if (flags & OPT_SHORT)
29                 return error("switch `%c' %s", opt->short_name, reason);
30         if (flags & OPT_UNSET)
31                 return error("option `no-%s' %s", opt->long_name, reason);
32         return error("option `%s' %s", opt->long_name, reason);
33 }
34
35 static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
36                    int flags, const char **arg)
37 {
38         if (p->opt) {
39                 *arg = p->opt;
40                 p->opt = NULL;
41         } else if (p->argc == 1 && (opt->flags & PARSE_OPT_LASTARG_DEFAULT)) {
42                 *arg = (const char *)opt->defval;
43         } else if (p->argc > 1) {
44                 p->argc--;
45                 *arg = *++p->argv;
46         } else {
47                 opterror(opt, "requires a value", flags);
48                 return -1;
49         }
50         return 0;
51 }
52
53 static void fix_filename(const char *prefix, const char **file)
54 {
55         if (!file || !*file || !prefix || is_absolute_path(*file)
56             || !strcmp("-", *file))
57                 return;
58         *file = xstrdup(prefix_filename(prefix, strlen(prefix), *file));
59 }
60
61 static int opt_command_mode_error(const struct option *opt,
62                                   const struct option *all_opts,
63                                   int flags)
64 {
65         const struct option *that;
66         struct strbuf message = STRBUF_INIT;
67         struct strbuf that_name = STRBUF_INIT;
68
69         /*
70          * Find the other option that was used to set the variable
71          * already, and report that this is not compatible with it.
72          */
73         for (that = all_opts; that->type != OPTION_END; that++) {
74                 if (that == opt ||
75                     that->type != OPTION_CMDMODE ||
76                     that->value != opt->value ||
77                     that->defval != *(int *)opt->value)
78                         continue;
79
80                 if (that->long_name)
81                         strbuf_addf(&that_name, "--%s", that->long_name);
82                 else
83                         strbuf_addf(&that_name, "-%c", that->short_name);
84                 strbuf_addf(&message, ": incompatible with %s", that_name.buf);
85                 strbuf_release(&that_name);
86                 opterror(opt, message.buf, flags);
87                 strbuf_release(&message);
88                 return -1;
89         }
90         return opterror(opt, ": incompatible with something else", flags);
91 }
92
93 static int get_value(struct parse_opt_ctx_t *p,
94                      const struct option *opt,
95                      const struct option *all_opts,
96                      int flags)
97 {
98         const char *s, *arg;
99         const int unset = flags & OPT_UNSET;
100         int err;
101
102         if (unset && p->opt)
103                 return opterror(opt, "takes no value", flags);
104         if (unset && (opt->flags & PARSE_OPT_NONEG))
105                 return opterror(opt, "isn't available", flags);
106         if (!(flags & OPT_SHORT) && p->opt && (opt->flags & PARSE_OPT_NOARG))
107                 return opterror(opt, "takes no value", flags);
108
109         switch (opt->type) {
110         case OPTION_LOWLEVEL_CALLBACK:
111                 return (*(parse_opt_ll_cb *)opt->callback)(p, opt, unset);
112
113         case OPTION_BIT:
114                 if (unset)
115                         *(int *)opt->value &= ~opt->defval;
116                 else
117                         *(int *)opt->value |= opt->defval;
118                 return 0;
119
120         case OPTION_NEGBIT:
121                 if (unset)
122                         *(int *)opt->value |= opt->defval;
123                 else
124                         *(int *)opt->value &= ~opt->defval;
125                 return 0;
126
127         case OPTION_COUNTUP:
128                 *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
129                 return 0;
130
131         case OPTION_SET_INT:
132                 *(int *)opt->value = unset ? 0 : opt->defval;
133                 return 0;
134
135         case OPTION_CMDMODE:
136                 /*
137                  * Giving the same mode option twice, although is unnecessary,
138                  * is not a grave error, so let it pass.
139                  */
140                 if (*(int *)opt->value && *(int *)opt->value != opt->defval)
141                         return opt_command_mode_error(opt, all_opts, flags);
142                 *(int *)opt->value = opt->defval;
143                 return 0;
144
145         case OPTION_STRING:
146                 if (unset)
147                         *(const char **)opt->value = NULL;
148                 else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
149                         *(const char **)opt->value = (const char *)opt->defval;
150                 else
151                         return get_arg(p, opt, flags, (const char **)opt->value);
152                 return 0;
153
154         case OPTION_FILENAME:
155                 err = 0;
156                 if (unset)
157                         *(const char **)opt->value = NULL;
158                 else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
159                         *(const char **)opt->value = (const char *)opt->defval;
160                 else
161                         err = get_arg(p, opt, flags, (const char **)opt->value);
162
163                 if (!err)
164                         fix_filename(p->prefix, (const char **)opt->value);
165                 return err;
166
167         case OPTION_CALLBACK:
168                 if (unset)
169                         return (*opt->callback)(opt, NULL, 1) ? (-1) : 0;
170                 if (opt->flags & PARSE_OPT_NOARG)
171                         return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
172                 if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
173                         return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
174                 if (get_arg(p, opt, flags, &arg))
175                         return -1;
176                 return (*opt->callback)(opt, arg, 0) ? (-1) : 0;
177
178         case OPTION_INTEGER:
179                 if (unset) {
180                         *(int *)opt->value = 0;
181                         return 0;
182                 }
183                 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
184                         *(int *)opt->value = opt->defval;
185                         return 0;
186                 }
187                 if (get_arg(p, opt, flags, &arg))
188                         return -1;
189                 *(int *)opt->value = strtol(arg, (char **)&s, 10);
190                 if (*s)
191                         return opterror(opt, "expects a numerical value", flags);
192                 return 0;
193
194         case OPTION_MAGNITUDE:
195                 if (unset) {
196                         *(unsigned long *)opt->value = 0;
197                         return 0;
198                 }
199                 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
200                         *(unsigned long *)opt->value = opt->defval;
201                         return 0;
202                 }
203                 if (get_arg(p, opt, flags, &arg))
204                         return -1;
205                 if (!git_parse_ulong(arg, opt->value))
206                         return opterror(opt,
207                                 "expects a non-negative integer value with an optional k/m/g suffix",
208                                 flags);
209                 return 0;
210
211         default:
212                 die("should not happen, someone must be hit on the forehead");
213         }
214 }
215
216 static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *options)
217 {
218         const struct option *all_opts = options;
219         const struct option *numopt = NULL;
220
221         for (; options->type != OPTION_END; options++) {
222                 if (options->short_name == *p->opt) {
223                         p->opt = p->opt[1] ? p->opt + 1 : NULL;
224                         return get_value(p, options, all_opts, OPT_SHORT);
225                 }
226
227                 /*
228                  * Handle the numerical option later, explicit one-digit
229                  * options take precedence over it.
230                  */
231                 if (options->type == OPTION_NUMBER)
232                         numopt = options;
233         }
234         if (numopt && isdigit(*p->opt)) {
235                 size_t len = 1;
236                 char *arg;
237                 int rc;
238
239                 while (isdigit(p->opt[len]))
240                         len++;
241                 arg = xmemdupz(p->opt, len);
242                 p->opt = p->opt[len] ? p->opt + len : NULL;
243                 rc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0;
244                 free(arg);
245                 return rc;
246         }
247         return -2;
248 }
249
250 static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
251                           const struct option *options)
252 {
253         const struct option *all_opts = options;
254         const char *arg_end = strchrnul(arg, '=');
255         const struct option *abbrev_option = NULL, *ambiguous_option = NULL;
256         int abbrev_flags = 0, ambiguous_flags = 0;
257
258         for (; options->type != OPTION_END; options++) {
259                 const char *rest, *long_name = options->long_name;
260                 int flags = 0, opt_flags = 0;
261
262                 if (!long_name)
263                         continue;
264
265 again:
266                 if (!skip_prefix(arg, long_name, &rest))
267                         rest = NULL;
268                 if (options->type == OPTION_ARGUMENT) {
269                         if (!rest)
270                                 continue;
271                         if (*rest == '=')
272                                 return opterror(options, "takes no value", flags);
273                         if (*rest)
274                                 continue;
275                         p->out[p->cpidx++] = arg - 2;
276                         return 0;
277                 }
278                 if (!rest) {
279                         /* abbreviated? */
280                         if (!strncmp(long_name, arg, arg_end - arg)) {
281 is_abbreviated:
282                                 if (abbrev_option) {
283                                         /*
284                                          * If this is abbreviated, it is
285                                          * ambiguous. So when there is no
286                                          * exact match later, we need to
287                                          * error out.
288                                          */
289                                         ambiguous_option = abbrev_option;
290                                         ambiguous_flags = abbrev_flags;
291                                 }
292                                 if (!(flags & OPT_UNSET) && *arg_end)
293                                         p->opt = arg_end + 1;
294                                 abbrev_option = options;
295                                 abbrev_flags = flags ^ opt_flags;
296                                 continue;
297                         }
298                         /* negation allowed? */
299                         if (options->flags & PARSE_OPT_NONEG)
300                                 continue;
301                         /* negated and abbreviated very much? */
302                         if (starts_with("no-", arg)) {
303                                 flags |= OPT_UNSET;
304                                 goto is_abbreviated;
305                         }
306                         /* negated? */
307                         if (!starts_with(arg, "no-")) {
308                                 if (starts_with(long_name, "no-")) {
309                                         long_name += 3;
310                                         opt_flags |= OPT_UNSET;
311                                         goto again;
312                                 }
313                                 continue;
314                         }
315                         flags |= OPT_UNSET;
316                         if (!skip_prefix(arg + 3, long_name, &rest)) {
317                                 /* abbreviated and negated? */
318                                 if (starts_with(long_name, arg + 3))
319                                         goto is_abbreviated;
320                                 else
321                                         continue;
322                         }
323                 }
324                 if (*rest) {
325                         if (*rest != '=')
326                                 continue;
327                         p->opt = rest + 1;
328                 }
329                 return get_value(p, options, all_opts, flags ^ opt_flags);
330         }
331
332         if (ambiguous_option)
333                 return error("Ambiguous option: %s "
334                         "(could be --%s%s or --%s%s)",
335                         arg,
336                         (ambiguous_flags & OPT_UNSET) ?  "no-" : "",
337                         ambiguous_option->long_name,
338                         (abbrev_flags & OPT_UNSET) ?  "no-" : "",
339                         abbrev_option->long_name);
340         if (abbrev_option)
341                 return get_value(p, abbrev_option, all_opts, abbrev_flags);
342         return -2;
343 }
344
345 static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg,
346                             const struct option *options)
347 {
348         const struct option *all_opts = options;
349
350         for (; options->type != OPTION_END; options++) {
351                 if (!(options->flags & PARSE_OPT_NODASH))
352                         continue;
353                 if (options->short_name == arg[0] && arg[1] == '\0')
354                         return get_value(p, options, all_opts, OPT_SHORT);
355         }
356         return -2;
357 }
358
359 static void check_typos(const char *arg, const struct option *options)
360 {
361         if (strlen(arg) < 3)
362                 return;
363
364         if (starts_with(arg, "no-")) {
365                 error ("did you mean `--%s` (with two dashes ?)", arg);
366                 exit(129);
367         }
368
369         for (; options->type != OPTION_END; options++) {
370                 if (!options->long_name)
371                         continue;
372                 if (starts_with(options->long_name, arg)) {
373                         error ("did you mean `--%s` (with two dashes ?)", arg);
374                         exit(129);
375                 }
376         }
377 }
378
379 static void parse_options_check(const struct option *opts)
380 {
381         int err = 0;
382         char short_opts[128];
383
384         memset(short_opts, '\0', sizeof(short_opts));
385         for (; opts->type != OPTION_END; opts++) {
386                 if ((opts->flags & PARSE_OPT_LASTARG_DEFAULT) &&
387                     (opts->flags & PARSE_OPT_OPTARG))
388                         err |= optbug(opts, "uses incompatible flags "
389                                         "LASTARG_DEFAULT and OPTARG");
390                 if (opts->short_name) {
391                         if (0x7F <= opts->short_name)
392                                 err |= optbug(opts, "invalid short name");
393                         else if (short_opts[opts->short_name]++)
394                                 err |= optbug(opts, "short name already used");
395                 }
396                 if (opts->flags & PARSE_OPT_NODASH &&
397                     ((opts->flags & PARSE_OPT_OPTARG) ||
398                      !(opts->flags & PARSE_OPT_NOARG) ||
399                      !(opts->flags & PARSE_OPT_NONEG) ||
400                      opts->long_name))
401                         err |= optbug(opts, "uses feature "
402                                         "not supported for dashless options");
403                 switch (opts->type) {
404                 case OPTION_COUNTUP:
405                 case OPTION_BIT:
406                 case OPTION_NEGBIT:
407                 case OPTION_SET_INT:
408                 case OPTION_NUMBER:
409                         if ((opts->flags & PARSE_OPT_OPTARG) ||
410                             !(opts->flags & PARSE_OPT_NOARG))
411                                 err |= optbug(opts, "should not accept an argument");
412                 default:
413                         ; /* ok. (usually accepts an argument) */
414                 }
415                 if (opts->argh &&
416                     strcspn(opts->argh, " _") != strlen(opts->argh))
417                         err |= optbug(opts, "multi-word argh should use dash to separate words");
418         }
419         if (err)
420                 exit(128);
421 }
422
423 void parse_options_start(struct parse_opt_ctx_t *ctx,
424                          int argc, const char **argv, const char *prefix,
425                          const struct option *options, int flags)
426 {
427         memset(ctx, 0, sizeof(*ctx));
428         ctx->argc = argc - 1;
429         ctx->argv = argv + 1;
430         ctx->out  = argv;
431         ctx->prefix = prefix;
432         ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
433         ctx->flags = flags;
434         if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
435             (flags & PARSE_OPT_STOP_AT_NON_OPTION))
436                 die("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
437         parse_options_check(options);
438 }
439
440 static int usage_with_options_internal(struct parse_opt_ctx_t *,
441                                        const char * const *,
442                                        const struct option *, int, int);
443
444 int parse_options_step(struct parse_opt_ctx_t *ctx,
445                        const struct option *options,
446                        const char * const usagestr[])
447 {
448         int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
449
450         /* we must reset ->opt, unknown short option leave it dangling */
451         ctx->opt = NULL;
452
453         for (; ctx->argc; ctx->argc--, ctx->argv++) {
454                 const char *arg = ctx->argv[0];
455
456                 if (*arg != '-' || !arg[1]) {
457                         if (parse_nodash_opt(ctx, arg, options) == 0)
458                                 continue;
459                         if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
460                                 return PARSE_OPT_NON_OPTION;
461                         ctx->out[ctx->cpidx++] = ctx->argv[0];
462                         continue;
463                 }
464
465                 if (arg[1] != '-') {
466                         ctx->opt = arg + 1;
467                         if (internal_help && *ctx->opt == 'h')
468                                 return parse_options_usage(ctx, usagestr, options, 0);
469                         switch (parse_short_opt(ctx, options)) {
470                         case -1:
471                                 return parse_options_usage(ctx, usagestr, options, 1);
472                         case -2:
473                                 if (ctx->opt)
474                                         check_typos(arg + 1, options);
475                                 goto unknown;
476                         }
477                         if (ctx->opt)
478                                 check_typos(arg + 1, options);
479                         while (ctx->opt) {
480                                 if (internal_help && *ctx->opt == 'h')
481                                         return parse_options_usage(ctx, usagestr, options, 0);
482                                 switch (parse_short_opt(ctx, options)) {
483                                 case -1:
484                                         return parse_options_usage(ctx, usagestr, options, 1);
485                                 case -2:
486                                         /* fake a short option thing to hide the fact that we may have
487                                          * started to parse aggregated stuff
488                                          *
489                                          * This is leaky, too bad.
490                                          */
491                                         ctx->argv[0] = xstrdup(ctx->opt - 1);
492                                         *(char *)ctx->argv[0] = '-';
493                                         goto unknown;
494                                 }
495                         }
496                         continue;
497                 }
498
499                 if (!arg[2]) { /* "--" */
500                         if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) {
501                                 ctx->argc--;
502                                 ctx->argv++;
503                         }
504                         break;
505                 }
506
507                 if (internal_help && !strcmp(arg + 2, "help-all"))
508                         return usage_with_options_internal(ctx, usagestr, options, 1, 0);
509                 if (internal_help && !strcmp(arg + 2, "help"))
510                         return parse_options_usage(ctx, usagestr, options, 0);
511                 switch (parse_long_opt(ctx, arg + 2, options)) {
512                 case -1:
513                         return parse_options_usage(ctx, usagestr, options, 1);
514                 case -2:
515                         goto unknown;
516                 }
517                 continue;
518 unknown:
519                 if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN))
520                         return PARSE_OPT_UNKNOWN;
521                 ctx->out[ctx->cpidx++] = ctx->argv[0];
522                 ctx->opt = NULL;
523         }
524         return PARSE_OPT_DONE;
525 }
526
527 int parse_options_end(struct parse_opt_ctx_t *ctx)
528 {
529         memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
530         ctx->out[ctx->cpidx + ctx->argc] = NULL;
531         return ctx->cpidx + ctx->argc;
532 }
533
534 int parse_options(int argc, const char **argv, const char *prefix,
535                   const struct option *options, const char * const usagestr[],
536                   int flags)
537 {
538         struct parse_opt_ctx_t ctx;
539
540         parse_options_start(&ctx, argc, argv, prefix, options, flags);
541         switch (parse_options_step(&ctx, options, usagestr)) {
542         case PARSE_OPT_HELP:
543                 exit(129);
544         case PARSE_OPT_NON_OPTION:
545         case PARSE_OPT_DONE:
546                 break;
547         default: /* PARSE_OPT_UNKNOWN */
548                 if (ctx.argv[0][1] == '-') {
549                         error("unknown option `%s'", ctx.argv[0] + 2);
550                 } else if (isascii(*ctx.opt)) {
551                         error("unknown switch `%c'", *ctx.opt);
552                 } else {
553                         error("unknown non-ascii option in string: `%s'",
554                               ctx.argv[0]);
555                 }
556                 usage_with_options(usagestr, options);
557         }
558
559         precompose_argv(argc, argv);
560         return parse_options_end(&ctx);
561 }
562
563 static int usage_argh(const struct option *opts, FILE *outfile)
564 {
565         const char *s;
566         int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;
567         if (opts->flags & PARSE_OPT_OPTARG)
568                 if (opts->long_name)
569                         s = literal ? "[=%s]" : "[=<%s>]";
570                 else
571                         s = literal ? "[%s]" : "[<%s>]";
572         else
573                 s = literal ? " %s" : " <%s>";
574         return utf8_fprintf(outfile, s, opts->argh ? _(opts->argh) : _("..."));
575 }
576
577 #define USAGE_OPTS_WIDTH 24
578 #define USAGE_GAP         2
579
580 static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
581                                        const char * const *usagestr,
582                                        const struct option *opts, int full, int err)
583 {
584         FILE *outfile = err ? stderr : stdout;
585
586         if (!usagestr)
587                 return PARSE_OPT_HELP;
588
589         if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
590                 fprintf(outfile, "cat <<\\EOF\n");
591
592         fprintf_ln(outfile, _("usage: %s"), _(*usagestr++));
593         while (*usagestr && **usagestr)
594                 /* TRANSLATORS: the colon here should align with the
595                    one in "usage: %s" translation */
596                 fprintf_ln(outfile, _("   or: %s"), _(*usagestr++));
597         while (*usagestr) {
598                 if (**usagestr)
599                         fprintf_ln(outfile, _("    %s"), _(*usagestr));
600                 else
601                         putchar('\n');
602                 usagestr++;
603         }
604
605         if (opts->type != OPTION_GROUP)
606                 fputc('\n', outfile);
607
608         for (; opts->type != OPTION_END; opts++) {
609                 size_t pos;
610                 int pad;
611
612                 if (opts->type == OPTION_GROUP) {
613                         fputc('\n', outfile);
614                         if (*opts->help)
615                                 fprintf(outfile, "%s\n", _(opts->help));
616                         continue;
617                 }
618                 if (!full && (opts->flags & PARSE_OPT_HIDDEN))
619                         continue;
620
621                 pos = fprintf(outfile, "    ");
622                 if (opts->short_name) {
623                         if (opts->flags & PARSE_OPT_NODASH)
624                                 pos += fprintf(outfile, "%c", opts->short_name);
625                         else
626                                 pos += fprintf(outfile, "-%c", opts->short_name);
627                 }
628                 if (opts->long_name && opts->short_name)
629                         pos += fprintf(outfile, ", ");
630                 if (opts->long_name)
631                         pos += fprintf(outfile, "--%s", opts->long_name);
632                 if (opts->type == OPTION_NUMBER)
633                         pos += utf8_fprintf(outfile, _("-NUM"));
634
635                 if ((opts->flags & PARSE_OPT_LITERAL_ARGHELP) ||
636                     !(opts->flags & PARSE_OPT_NOARG))
637                         pos += usage_argh(opts, outfile);
638
639                 if (pos <= USAGE_OPTS_WIDTH)
640                         pad = USAGE_OPTS_WIDTH - pos;
641                 else {
642                         fputc('\n', outfile);
643                         pad = USAGE_OPTS_WIDTH;
644                 }
645                 fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", _(opts->help));
646         }
647         fputc('\n', outfile);
648
649         if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
650                 fputs("EOF\n", outfile);
651
652         return PARSE_OPT_HELP;
653 }
654
655 void NORETURN usage_with_options(const char * const *usagestr,
656                         const struct option *opts)
657 {
658         usage_with_options_internal(NULL, usagestr, opts, 0, 1);
659         exit(129);
660 }
661
662 void NORETURN usage_msg_opt(const char *msg,
663                    const char * const *usagestr,
664                    const struct option *options)
665 {
666         fprintf(stderr, "%s\n\n", msg);
667         usage_with_options(usagestr, options);
668 }
669
670 static int parse_options_usage(struct parse_opt_ctx_t *ctx,
671                                const char * const *usagestr,
672                                const struct option *opts, int err)
673 {
674         return usage_with_options_internal(ctx, usagestr, opts, 0, err);
675 }
676