[issue11695] Improve argparse usage/help customization

2014-06-21 Thread paul j3

paul j3 added the comment:

That original template can also be implemented with a customized 'format_help':

def custom_help(self):
formatter = self._get_formatter()
formatter.add_text('My Program, version 3.5')
formatter.add_usage(self.usage, self._actions,
self._mutually_exclusive_groups,
prefix='Usage: ')
formatter.add_text('Some description of my program')
for action_group in self._action_groups:
with formatter.add_section(action_group.title):
formatter.add_text(action_group.description)
formatter.add_arguments(action_group._group_actions)
formatter.add_text('My epilog text')
return formatter.format_help()

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11695] Improve argparse usage/help customization

2014-06-20 Thread paul j3

paul j3 added the comment:

This patch has a 'custom_help' which, with a default template, is compatible 
with 'format_help' (i.e. it passes test_argparse).  It also handles the sample 
template in this issue.

Due to long line wrapping issues, the 'Usage: ' string the test template has to 
be entered separately as a usage 'prefix'.  Indenting of long wrapped values 
(like usage) is correct only if the '%(...)s' string is at the start of a line.

I see this as a test-of-concept patch.

--
keywords: +patch
Added file: http://bugs.python.org/file35713/issue11695_1.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11695] Improve argparse usage/help customization

2014-06-19 Thread paul j3

paul j3 added the comment:

Here's a function that implements the format string:

def custom_help(template):
def usage(self):
formatter = self._get_formatter()
formatter.add_usage(self.usage, self._actions,
self._mutually_exclusive_groups, prefix='')
return formatter.format_help().strip()
def groups(self):
formatter = self._get_formatter()
for action_group in self._action_groups:
 formatter.start_section(action_group.title)
 formatter.add_text(action_group.description)
 formatter.add_arguments(action_group._group_actions)
 formatter.end_section()
astr = formatter.format_help().rstrip()
return astr
dd = dict(
usage=usage(parser),
argument_groups=groups(parser),
)
return template%dd

 template = My Program, version 3.5
 Usage: %(usage)s

 Some description of my program

 %(argument_groups)s

 My epilog text
 
 print(custom_help(template))

This replaces 'parser.format_help' rather than the 'HelpFormatter' class.  It 
in effect uses pieces from 'format_help' to format strings like 'usage', and 
plugs those into the template.

While a template based formatter could be implemented as Formatter subclass, it 
seems to be an awkward fit.  In the current structure, the 'parser' method 
determines the overall layout of 'help', while the 'formatter' generates the 
pieces.  The proposed template deals with the layout, not the pieces.

'format_help' could cast into this form, using a default template.  

Possible generalization include:
- methods to format other parts of the help
- handling of multiline indented blocks
- utilizing other templating tools (string.Template, Py3 format, Mako)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11695] Improve argparse usage/help customization

2014-06-16 Thread Mark Lawrence

Changes by Mark Lawrence breamore...@yahoo.co.uk:


--
nosy: +paul.j3
versions: +Python 2.7, Python 3.5 -Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11695] Improve argparse usage/help customization

2013-01-09 Thread John O'Connor

Changes by John O'Connor tehj...@gmail.com:


--
nosy: +jcon

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11695] Improve argparse usage/help customization

2013-01-09 Thread Chris Jerdonek

Chris Jerdonek added the comment:

+1 to the feature.

A closely-related use case is customizing the message displayed by error(), 
which is normally the usage string followed by the error message.  I wanted to 
append instructions on how to invoke --help, and implemented it this way for 
CPython's regrtest:

http://hg.python.org/cpython/file/6ee721029fd5/Lib/test/regrtest.py#l205

Also take a look at how regrtest formats its usage string as another use case 
to satisfy:

http://hg.python.org/cpython/file/6ee721029fd5/Lib/test/regrtest.py#l9

It seems like many argparse customizations take the form of override this 
method.  Would it make sense for the API to be for customizers to override 
string-returning methods like make_usage() and make_error() (and that accept a 
dictionary)?  That may give a bit more control than a format string.

--
nosy: +chris.jerdonek

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11695] Improve argparse usage/help customization

2012-01-16 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
nosy: +berkerpeksag

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11695] Improve argparse usage/help customization

2011-06-21 Thread Petri Lehtinen

Changes by Petri Lehtinen pe...@digip.org:


--
nosy: +petri.lehtinen

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11695] Improve argparse usage/help customization

2011-03-27 Thread Steven Bethard

New submission from Steven Bethard steven.beth...@gmail.com:

I'm going to try to merge several closely related issues here. Basically, 
people would like better control over the usage message formatting so that you 
could:

* Put program name and version information at the top of the message
* Customize the usage: string (e.g. capitalize it)

One proposal from anatoly techtonik would be to allow a format string so that 
you could write something like

My Program, version 3.5
Usage: %(usage)s

Some description of my program

%(argument_groups)%

My epliog text


This should be implemented as a HelpFormatter class, but we might have to 
expose a little more of the HelpFormatter API (which is currently documented as 
a no-public API) to make this possible.

Patches welcome. ;-)

--
components: Library (Lib)
messages: 132322
nosy: bethard
priority: normal
severity: normal
stage: needs patch
status: open
title: Improve argparse usage/help customization
type: feature request
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11695
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com