Message198038
This is a HelpFormatter function that takes a list of formatted actions, and groups contiguous blocks of optional positional actions. It accounts for optionals (via prefix_chars) and mutually exclusive groups.
Since it assumes 'parts' is a list, rather than string, it works best with the '_format_actions_usage' method in the patch that I submitted to http://bugs.python.org/issue11874
def _positionals_regroup(self, parts):
# change '[arg1] [arg2]' to '[arg1 [arg2]]'
# apply to a list of formatted arguments
# don't apply to optionals (with prefix chars) or groups
chars = getattr(self, 'prefix_chars',set('-'))
R = _re.compile(r'\] \[(.*)\]')
result = []
text = None
while parts:
part = parts.pop()
if part:
if part[0]=='[' and part[1] not in chars and '|' not in part:
if text:
text = ' '.join([part, text])
else:
text = part
if R.search(text):
text = R.sub(' [\g<1>]]',text)
else:
if text:
result.insert(0,text)
text = None
result.insert(0,part)
if text:
result.insert(0,text)
return result
To avoid compatibility issues it could implemented in a subclassed HelpFormatter. |
|
Date |
User |
Action |
Args |
2013-09-19 01:40:57 | paul.j3 | set | recipients:
+ paul.j3, bethard, pwil3058, petri.lehtinen |
2013-09-19 01:40:57 | paul.j3 | set | messageid: <1379554857.35.0.777539053411.issue11708@psf.upfronthosting.co.za> |
2013-09-19 01:40:57 | paul.j3 | link | issue11708 messages |
2013-09-19 01:40:56 | paul.j3 | create | |
|