Message173659
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 |
|
Date |
User |
Action |
Args |
2012-10-24 09:22:33 | telmich | set | recipients:
+ telmich |
2012-10-24 09:22:33 | telmich | set | messageid: <1351070553.1.0.217274613803.issue16308@psf.upfronthosting.co.za> |
2012-10-24 09:22:33 | telmich | link | issue16308 messages |
2012-10-24 09:22:32 | telmich | create | |
|