| msg128300 - (view) |
Author: Steven Bethard (bethard) *  |
Date: 2011-02-10 15:45 |
| Suggestion from a personal email: I generally like my command line arguments that take a value to specify the type, e.g., --runs int how many runs to do Naturally I can do this using the metavars argument in every add_argument() call, but that can become tedious. So I suggest adding a metavars argument to the ArgumentParser constructor; default metavars=None (current behaviour); metavars=type (show type names). And of course, allow metavars specified in add_argument() calls to override on a case by case basis. |
|
|
| msg129577 - (view) |
Author: Filip GruszczyĆski (gruszczy) |
Date: 2011-02-26 17:30 |
| First draft of patch with this functionality. Test, patch and docs are included. I'll gladly work further on this, so I would appreciate some advice and suggestions. |
|
|
| msg132230 - (view) |
Author: Steven Bethard (bethard) *  |
Date: 2011-03-26 12:16 |
| Sorry about such a slow response on this. Thanks for the patch! I think rather than adding an ArgumentParser constructor parameter though, we should add a new formatter class. The attached patch allows you to write: >>> parser = argparse.ArgumentParser( ... prog='PROG', ... formatter_class=argparse.MetavarTypeHelpFormatter) >>> parser.add_argument('--foo', type=int) >>> parser.add_argument('bar', type=float) >>> parser.print_help() usage: PROG [-h] [--foo int] float positional arguments: float optional arguments: -h, --help show this help message and exit --foo int What do you think? |
|
|
| msg132231 - (view) |
Author: Filip GruszczyĆski (gruszczy) |
Date: 2011-03-26 12:23 |
| Well, since you are the designer of the package, I believe you have better knowledge on how to extend it :-). I just provided a patch according to what you described in the first message. Anyway having separate help formatter seems better than bloating parser's constructor. |
|
|
| msg132237 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2011-03-26 13:48 |
| New changeset a15d65d8f269 by Steven Bethard in branch 'default': Issue #11174: Add argparse.MetavarTypeHelpFormatter, which uses type names http://hg.python.org/cpython/rev/a15d65d8f269 |
|
|
| msg253197 - (view) |
Author: paul j3 (paul.j3) *  |
Date: 2015-10-19 21:33 |
| This formatter produces an error if one or more of the arguments uses the default `None` type (a string). This is because `None` does not have a `.__name__`. This HelpFormatter probably has been rarely, if ever, used. The metavar parameter works just as well. |
|
|