zenlotus / argparse

Automatically exported from code.google.com/p/argparse
Other
0 stars 0 forks source link

Show defaults in --help #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
[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. 

Original issue reported on code.google.com by steven.b...@gmail.com on 28 Mar 2009 at 2:08

GoogleCodeExporter commented 9 years ago
I'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?

Original comment by steven.b...@gmail.com on 28 Mar 2009 at 2:09

GoogleCodeExporter commented 9 years ago
I, 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.

Original comment by robert.kern@gmail.com on 6 Jun 2009 at 10:06

GoogleCodeExporter commented 9 years ago
Yeah, 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.

Original comment by steven.b...@gmail.com on 10 Jun 2009 at 2:18

GoogleCodeExporter commented 9 years ago
I 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.

Original comment by steven.b...@gmail.com on 13 Jul 2009 at 12:04