Message218397
An alternative to adding a 'ParagraphFormatter' class to 'argparse', is to format the individual text blocks PRIOR to passing them to the 'parser', and use the 'RawTextHelpFormatter'.
In the attached script I use a simple function that applies 'textwrap' to each 'line' of the text. Description, epilog, and argument help are formatted in roughly the same manner as in paraformatter.py, but without as many bells and whistles.
def mywrap(text,**kwargs):
# apply textwrap to each line individually
text = text.splitlines()
text = [textwrap.fill(line,**kwargs) for line in text]
return '\n'.join(text)
parser = argparse.ArgumentParser( formatter_class = argparse.RawTextHelpFormatter,
description = mywrap(description),
epilog = mywrap(epilog, width=40))
I suspect there are tools for doing similar formatting, starting with 'markdown' or 'rsT' paragraphs (though HTML is the usual output). As the formatting becomes more complex it is better to use existing tools than to write something new for 'argparse'. |
|
Date |
User |
Action |
Args |
2014-05-13 02:54:57 | paul.j3 | set | recipients:
+ paul.j3, bethard, eric.araujo, zbysz, denilsonsa, rurpy2, GraylinKim |
2014-05-13 02:54:57 | paul.j3 | set | messageid: <1399949697.44.0.529338761123.issue12806@psf.upfronthosting.co.za> |
2014-05-13 02:54:57 | paul.j3 | link | issue12806 messages |
2014-05-13 02:54:57 | paul.j3 | create | |
|