This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients GraylinKim, bethard, denilsonsa, eric.araujo, paul.j3, rurpy2, zbysz
Date 2014-05-13.02:54:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1399949697.44.0.529338761123.issue12806@psf.upfronthosting.co.za>
In-reply-to
Content
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'.
History
Date User Action Args
2014-05-13 02:54:57paul.j3setrecipients: + paul.j3, bethard, eric.araujo, zbysz, denilsonsa, rurpy2, GraylinKim
2014-05-13 02:54:57paul.j3setmessageid: <1399949697.44.0.529338761123.issue12806@psf.upfronthosting.co.za>
2014-05-13 02:54:57paul.j3linkissue12806 messages
2014-05-13 02:54:57paul.j3create