# Re: \[PATCH v3 3/4\] parse-options: add early\_scan\_options()

- From: Christian Couder \<hidden\>
- Date: 2026-11-02 15:25:43 
- List: git
- Page: https://ratatoskr.run/git/2026/11/17845583
- Thread: https://ratatoskr.run/git/2026/09/17499453/t.md

```text
On Fri, Oct 30, 2026 at 10:27 PM Kaartic Sivaraam
[ref] wrote:
>
> On 10/12/26 13:14, Christian Couder wrote:

> > @@ -763,6 +765,8 @@ static void parse_options_check(const struct option *opts)
> >               case OPTION_SUBCOMMAND:
> >                       if (!opts->value || !opts->subcommand_fn)
> >                               optbug(opts, "OPTION_SUBCOMMAND needs a value and a subcommand function");
> > +                     if (opts->flags & PARSE_OPT_EARLY)
> > +                             optbug(opts, "OPTION_SUBCOMMAND does not support PARSE_OPT_EARLY");
> >                       if (!subcommand_value)
> >                               subcommand_value = opts->value;
> >                       else if (subcommand_value != opts->value)
>
> Would it make sense to also have these validations within
> early_scan_options() just in case it is called before
> parse_options_start() is invoked?

Yeah, I think it's cheap and simple enough to just call
parse_options_check() from early_scan_options(), so I have added that
call in the v4 I just sent.


> > +/*
> > + * Called by early_scan_options() for each argument matching a
> > + * `struct option` with PARSE_OPT_EARLY set.
> > + *
> > + * - `option` is the matching option,
>
> Would it be helpful to also convey here that the caller is not expected
> to retain the pointer as the memory pointing to it would be freed once
> the scan completes?

Yeah, it looks like this in v4:

 * - `option` is the matching option, (may point into a temporary
 *   copy of the options, so must not be used after the scan,)

Thanks.
```
