Message326596
An alternative to customizing a HelpFormatter is to write your own utility `add_argument` function, e.g.
def my_add_argument(parser, *args, add_default=True, **kwargs):
if add_default:
help = kwargs.get('help','')
help += ' (default: %(default)s)'
kwargs['help'] = help
return parser.add_argument(*args, **kwargs)
which could be used as
my_add_argument(parser, '-g', help='bar help', default='other', add_default=False)
There are some refinements to the _get_help_string() that I showed earlier, such as only adding the '%s' to actions where default makes sense (optionals and a subset positionals). One could also skip it if the default is the default default None, etc.
One way or other the user can already control whether the help line shows the default. ArgumentDefaultsHelpFormatter just automates this for a straight forward parser.
I'm going to close this issue since it isn't really needed (and no one has proposed a clever patch). |
|
Date |
User |
Action |
Args |
2018-09-27 21:11:14 | paul.j3 | set | recipients:
+ paul.j3, elypter |
2018-09-27 21:11:14 | paul.j3 | set | messageid: <1538082674.27.0.545547206417.issue32552@psf.upfronthosting.co.za> |
2018-09-27 21:11:14 | paul.j3 | link | issue32552 messages |
2018-09-27 21:11:14 | paul.j3 | create | |
|