Pierre Habouzit <madcoder@xxxxxxxxxx> writes: > If you set this for a given flag, and the flag appears without a value on > the command line, then the `defval' is used to fake a new argument. > > Note that this flag is meaningless in presence of OPTARG or NOARG flags. > (in the current implementation it will be ignored, but don't rely on it). > > Signed-off-by: Pierre Habouzit <madcoder@xxxxxxxxxx> > --- > > > (3) inspired from (1) and (2), have a flag for options that says > > "I do take an argument, but if I'm the last option on the > > command line, please fake this argument for me. > > > > I really like (3) more FWIW as it doesn't generate ambiguous > > parsers like (2) would, and it's not horrible like (1). And cherry > > on top it's pretty trivial to implement I think. Yeah, I do not particularly want a major rewrite that only introduces possible ambiguity to the option parser (even though arguably it would add to the usability very much, just like we accept revs and paths when unambiguous), so I think this is a reasonable compromise. It feels more like LASTARG_DEFAULT but that is bikeshedding ;-) But I see one thinko (fix below) and another issue I am not sure what the best fix would be. --- diff --git a/parse-options.c b/parse-options.c index b6735a5..cba20d7 100644 --- a/parse-options.c +++ b/parse-options.c @@ -26,11 +26,11 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, if (p->opt) { *arg = p->opt; p->opt = NULL; + } else if (p->argc == 1 && (opt->flags & PARSE_OPT_FAKELASTARG)) { + *arg = (const char *)opt->defval; } else if (p->argc) { p->argc--; *arg = *++p->argv; - } else if (opt->flags & PARSE_OPT_FAKELASTARG) { - *arg = (const char *)opt->defval; } else return opterror(opt, "requires a value", flags); return 0; -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html