This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author telmich
Recipients telmich
Date 2012-10-24.09:22:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1351070553.1.0.217274613803.issue16308@psf.upfronthosting.co.za>
In-reply-to
Content
Using argparse with subparsers, the default behaviour if no subparser was selected, was to print help:

cdist% git describe 
2.0.14-59-g5315c41
cdist% ./bin/cdist 
usage: cdist [-h] [-d] [-v] [-V] {banner,config} ...
cdist: error: too few arguments
cdist% python3 -V 
Python 3.2.3

With python 3.3.0, this changed and thus the so far uncalled code block is executed:

cdist% ./bin/cdist  
Traceback (most recent call last):
  File "./bin/cdist", line 237, in <module>
    commandline()
  File "./bin/cdist", line 104, in commandline
    args.func(args)
AttributeError: 'Namespace' object has no attribute 'func'
cdist% git describe 
2.0.14-59-g5315c41
cdist% python3 -V
Python 3.3.0


Question:

What is the correct way now to abort, if no subparser or
no option was given (i.e. restore the previous behaviour)?

I tried to fix this problem by using

parser['main'].set_defaults(func=commandline_main)

to setup a default handler for main, but this overwrites the func= parameter for all subparsers as well and thus renders this possibility useless (commits b7a8a84 and 840dbc5 in cdist).

The source code for cdist using the subparsers is available at http://git.schottelius.org/?p=cdist
History
Date User Action Args
2012-10-24 09:22:33telmichsetrecipients: + telmich
2012-10-24 09:22:33telmichsetmessageid: <1351070553.1.0.217274613803.issue16308@psf.upfronthosting.co.za>
2012-10-24 09:22:33telmichlinkissue16308 messages
2012-10-24 09:22:32telmichcreate