classification
Title: Enhance argparse help output customizability
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Improve argparse usage/help customization
View: 11695
Assigned To: Nosy List: Tom.Browder, bethard, r.david.murray, terry.reedy
Priority: normal Keywords:

Created on 2010-08-20 20:56 by Tom.Browder, last changed 2011-03-27 14:09 by bethard. This issue is now closed.

Files
File name Uploaded Description Edit
python-v2.7-argparser-patch.txt Tom.Browder, 2010-08-20 20:56 Proposed patch for Python 2.7
Messages (5)
msg114455 - (view) Author: Tom Browder (Tom.Browder) Date: 2010-08-20 20:56
I would like to be able to change argparse default strings so the first word is capitalized.  In lieu of that, I propose the attached patch to 2.7 which changes them in the source code.
msg115082 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-08-27 14:27
Looks like "usage" is almost always lowercase in the programs I tried (ssh, svn, cat, etc.). So it probably wouldn't be a good idea to change the default. Seems like both this and issue 9694 need a better way to customize the text in argparse mesages.

As a temporary workaround for the group names, you can try:

parser._optionals.title = "Optional arguments"
parser._positionals.title = "Positional arguments"

I can't guarantee this will continue to work since it relies on internal details but at least it would work for the time being.
msg115108 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-27 18:14
2.7 is closed to new features and I cannot see making a non-bug change in a maintenance release that could break something.

Should this be closed in favor of #9694? (Or vice versa?). Perhaps one of the issues should be renamed something like "Improve argparse message customization".
msg115126 - (view) Author: Tom Browder (Tom.Browder) Date: 2010-08-27 20:08
...
> Should this be closed in favor of #9694? (Or vice versa?). Perhaps one of the issues should be renamed something like "Improve argparse message customization".

That sounds like a winner to me

-Tom
msg132325 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2011-03-27 14:09
I'm moving this over to Issue 11695, which proposes support for a usage/help message template.

To customize the argument group names, the recommended approach is to create your own argument groups, and only put arguments there, e.g.:

parser = argparse.ArgumentParser(add_help=False)
flags = parser.add_argument_group('My Optional Arguments')
flags.add_argument('-h', '--help', action='help')
flags.add_argument('-v', action='version', version='1.3')

Then you'll get just the "My Optional Arguments" heading.
History
Date User Action Args
2011-03-27 14:09:31bethardsetstatus: open -> closed
resolution: duplicate
messages: + msg132325

superseder: Improve argparse usage/help customization
stage: test needed -> resolved
2010-08-27 21:30:25r.david.murraysettitle: Tidy argparse default output -> Enhance argparse help output customizability
2010-08-27 20:08:30Tom.Browdersetmessages: + msg115126
title: Enhance argparse help output customizability -> Tidy argparse default output
2010-08-27 19:16:55r.david.murraysetnosy: + r.david.murray
2010-08-27 19:16:39r.david.murraysettitle: Tidy argparse default output -> Enhance argparse help output customizability
2010-08-27 18:14:10terry.reedysetversions: + Python 3.2, - Python 2.7
nosy: + terry.reedy

messages: + msg115108

stage: test needed
2010-08-27 14:27:25bethardsetmessages: + msg115082
2010-08-27 12:46:13r.david.murraysetnosy: + bethard
2010-08-20 20:56:57Tom.Browdercreate