I have the following test code:
import argparse
myparser = argparse.ArgumentParser(prog='test')
myparser.add_argument('mode', choices=['A', 'B'])
subparsers = myparser.add_subparsers()
a_parser = subparsers.add_parser('A')
b_parser = subparsers.add_parser('B')
a_parser.add_argument('frog',action='store')
b_parser.add_argument('toad',action='store')
print(myparser)
try:
args = myparser.parse_args(['A', 'frogname'])
print(args)
except ArgumentError as ae:
print(ae)
When I run it I get the following:
ArgumentParser(prog='test', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
usage: test [-h] {A,B} {A,B} ...
test: error: invalid choice: 'frogname' (choose from 'A', 'B')
I'm not sure why I'm getting multiple copies of the 'mode' argument or why my subparsers are being ignored.