[Originally reported by yanghatespam@gmail.com to the python-hosting.org tracker]
It would be great if --help would also show the default values for options (where applicable), or at least if this feature were exposed as an option in argparse.
Comment #1
Posted on Mar 28, 2009 by Grumpy RabbitI'm a little nervous about doing this for all help messages because sometimes the Python object used as a default doesn't make sense (e.g. a function object). You can use string format specifiers in the help messages though, like this::
parser = argparse.ArgumentParser() parser.add_argument('--foo', type=int, default=123, ... help='Foo something (default: %(default)s)') parser.print_help() usage: argparse.py [-h] [--foo FOO]
optional arguments: -h, --help show this help message and exit --foo FOO Foo something (default: 123)
Is that enough, or are you hoping for a help formatter that automatically adds (default: xxx) to the end of everything with a non-None default?
Comment #2
Posted on Jun 6, 2009 by Happy PandaI, for one, would like to see such a formatter. It should probably try to check that '%(default)' is not already in the string, though. I might want to override the formatting for one argument.
Comment #3
Posted on Jun 10, 2009 by Grumpy RabbitYeah, checking for '%(default)' makes a lot of sense. I'll try to add this feature before the next release of argparse. It'll probably come in the form of a new subclass of HelpFormatter.
Comment #4
Posted on Jul 13, 2009 by Grumpy RabbitI finally got around to this. There's now a ArgumentDefaultsHelpFormatter as of r28 which adds ' (default: %(default)s)' to all the help strings where the argument has a default.
Status: Fixed
Labels:
Type-Enhancement
Priority-Low