Negating options
Denys Duchier
duchier at ps.uni-sb.de
Mon Feb 6 14:20:26 GMT 2006
John A Meinel <john at arbash-meinel.com> writes:
> This requires that global options occur before the command. People
> didn't like this. --quiet, --no-plugins should all be 'global' commands,
No, it doesn't. --no-plugins is a bit special, so yes that one needs to occur
early. But a --quiet global option does not have to occur before the command:
that is why my description suggested to _extend_ the parser with the command
specific options. In this manner, nested subcommands always permit options of
super commands to be interspersed with their own. I am not speaking
theoretically: I have actually tested this type of layered processing.
> So is there another way to have optparse handle this? Does it have
> "don't complain about unknown args" so that we can run one pass with the
> global option parser, and then run a second pass with the command
> specific one?
It is not possible to safely proceed in this fashion because during a 1st pass
you might not be aware of argument-taking options for the 2nd pass. If
--no-plugins were actually supposed to be the argument value for a subcommand
option: extracting it on the 1st pass whould completely mess things up.
That's why I suggested the allow_interspersed_args=False based method of
iterative processing: only parse up to the first non recognized argument: if
that one is a subcommand, then extend the parser with options for that
subcommand and process the rest of the leftover. repeat until done.
Cheers,
--Denys
More information about the bazaar
mailing list