paul j3 added the comment:

In http://bugs.python.org/issue11588 (Add "necessarily inclusive" groups to 
argparse) I propose a generalization to these testing groups that would solve 
your 'conflicter' case as follows:

    usage = 'prog [ --conflicter | [ --opt1 ] [ --opt2 ] ]'
    parser = argparse.ArgumentParser(usage=usage)
    conflicter = parser.add_argument("--conflicter", action='store_true')
    opt1 = parser.add_argument("--opt1", action='store_true')
    opt2 = parser.add_argument("--opt2", action='store_true')

    @parser.crosstest
    def test(parser, seen_actions, *args):
        if conflicter in seen_actions:
            if 0<len(seen_actions.intersection([opt1, opt2])):
                parser.error('--conflicter cannot be used with --opt1 or 
--opt2')

Groups, as currently defined, cannot handle nesting, and as a consequence 
cannot handle complex logic.  My proposal is to replace groups with user 
defined conflict tests that would be run near the end of 'parse_args'.  

This example shows, I think, that the proposal is powerful enough.  I'm not 
sure about ease of use and logical transparency.

Formatting the usage line is a different issue, though the 
MultiGroupHelpFormatter that I propose here is a step in the right direction.  
For now a user written 'usage' is the simplest solution.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10984>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to