the latest argparse
release changed how it tested for required arguments, and subparsers fell through the cracks. They are no longer 'required'. http://bugs.python.org/issue9253#msg186387
When you get test.py: error: too few arguments
, it's objecting that you did not give it a 'subcommand' argument. In 3.3.5 it makes it past that step, and returns args
.
With this change, 3.3.5 should behave the same as earlier versions:
ap = ArgumentParser()
sp = ap.add_subparsers(dest='parser') # dest needed for error message
sp.required = True # force 'required' testing
Note - both dest
and required
need to be set. dest
is needed to give this argument a name in the error message.
This error:
AttributeError: 'Namespace' object has no attribute 'do'
was produced because the cmd
subparser did not run, and did not put its arguments (default or not) into the namespace. You can see that effect by defining another subparser, and looking at the resulting args
.