Re: [PATCH 1/2] parse_options: Add flag to prevent errors for further processing
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jun 22, 2008, 19:07 UTC
- Message-ID
- <alpine.DEB.1.00.0806221953470.6439@racer>
- In-Reply-To
- <20080619142527.GA8429@mediacenter>
Hi,
On Thu, 19 Jun 2008, Shawn Bohrer wrote:
Show 39 quoted lines
> On Wed, Jun 18, 2008 at 11:52:42AM -0700, Junio C Hamano wrote:
> > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> >
> > > On Tue, 17 Jun 2008, Junio C Hamano wrote:
> > >
> > >> Jeff King <peff@peff.net> writes:
> > >>
> > >> > I think the only right way to accomplish this is to convert the
> > >> > revision and diff parameters into a parseopt-understandable
> > >> > format.
> > >>
> > >> Not necessarily. You could structure individual option parsers
> > >> like how diff option parsers are done. You iterate over argv[],
> > >> feed diff option parser the current index into argv[] and ask if it
> > >> is an option diff understands, have diff eat the option (and
> > >> possibly its parameter) to advance the index, or allow diff option
> > >> to say "I do not understand this", and then handle it yourself or
> > >> hand it to other parsers.
> > >
> > > AFAIR Pierre tried a few ways, and settled with a macro to introduce
> > > the diff options into a caller's options.
> > >
> > > IOW it would look something like this:
> > >
> > > static struct option builtin_what_options[] = {
> > > [... options specific to this command ...]
> > > DIFF__OPT(&diff_options)
> > > };
> >
> > I think that is the more painful approach Jeff mentioned, and my
> > comment was to show that it is not the only way.
> >
>
> It seems to me that you could implement Jeff's
> PARSE_OPT_STOP_AT_UNKNOWN, and then if multiple option parsers are
> needed you would simply loop over parse_options for each of the
> commands, waiting for argc to stop changing. Of course Jeff's flag
> would also need to stop parse_options from eating the first argument. Is
> this sort of what you are suggesting Junio?I believe not. I think that Junio prefers some callback that can handle a whole bunch of options (as opposed to the callback we can have now, to handle arguments for a specific option).
However, I am not sure what that would buy us over the approach Pierre settled. Junio, maybe you thought that the option parsing macro would live in parse-options.h? It was supposed to live in diff.h and revision.h, respectively.
Ciao, Dscho