◐ Shell
clean mode source ↗

Message 276503 - Python tracker

Clint, 'nargs=argparser.REMAINDER' ('...') may do what you want

    p=argparse.ArgumentParser()
    p.add_argument('--subscipt_args', nargs='...')
    p.add_argument('pos',nargs='*')

    p.parse_args('--subscipt_args --foo --bar --baz -- other args'.split())

produces

    Namespace(pos=['other', 'args'], subscipt_args=['--foo', '--bar', '--baz'])

'REMAINDER' is like '*' except it takes everything.  But the '--' means 'everything that follows is a positional argument, so it effectively ends the 'REMAINDER'.  'REMAINDER' is documented (briefly), but I don't recall reading about its interaction with '--'.  I'm a little surprised that it wasn't mentioned earlier in this bug/issue.

'+...', argparse.PARSER is similar except it requires at least one argument.  It is used by the 'subparsers' argument, to collect the cmd string and use all that follow as subparser arguments.

There is a bug issue (or two) about what should happen when there are more than one '--' argument.