nargs.REMAINDER not eating all args

55 views
Skip to first unread message

Michael Edwards

unread,
Nov 22, 2012, 12:25:24 PM11/22/12
to argpars...@googlegroups.com
I have some argparse code included below. In it I try to eat a --browsers with nargs=* and a --remote-url string arg. Both are optional. Anything else should be passed on to another application using argparse.REMAINDER. However, if I execute 'app --param-meant-for-lettuce blah' then my argparser complains instead of passing it on to the other app. Most other use cases appear to work fine (ie 'app somebarparamforotherapp' executes fine). Am I doing something wrong or is this an argparse defect? According to the documentation this should work. I'm executing this under Python 2.6 and 2.7.

--thanks
medwards

# Full file is available at https://github.com/medwards/salad/blob/4512a69f508660c11472f879b94649bf0934f317/salad/cli.py
def main(args=sys.argv[1:]):
    parser = argparse.ArgumentParser(prog="Salad", description='BDD browswer-automation made tasty.')

    parser.add_argument('--browsers', default=DEFAULT_BROWSERS, nargs='*'
                        metavar='BROWSER', choices=BROWSER_CHOICES,
                        help=('List of browsers to use. Default is %s.' %
                              DEFAULT_BROWSERS))
    parser.add_argument('--remote-url',
                        help='Selenium server url to use for browsers')
    parser.add_argument('args', nargs=argparse.REMAINDER)

    parsed_args = parser.parse_args()
    world.drivers = parsed_args.browsers
    world.remote_url = parsed_args.remote_url
    lettuce_main(args=parsed_args.args)

Reply all
Reply to author
Forward
0 new messages