#!/usr/bin/python
"""Generates a manual page from a module using argparse."""

from argparse import ArgumentParser
from re import compile, DOTALL

# Do not modify ArgumentParser yet. First, it is needed proper for this program itself.

parser = ArgumentParser(description="Generates a manpage from an argparse help text.")
parser.short = __doc__
parser.add_argument('module', help="module to generate manpage for")
parser.add_argument('-d', '--short', metavar="DESCRIPTION", help="""
        Specifies a short description to add in the NAME section. This can also be set
        on the ArgumentParser itself by assigning it an attribute 'short'. This will
        be the summary shown by apropos. When not given, this will just consist
        of the executable name. The inherent description text given at ArgumentParser
        construction will always end up in the DESCRIPTION section.""")
parser.add_argument('-s', '--suite', help="""Specifies the suite to insert into the header.
        If not given and the program sets an attribute 'suite' on its ArgumentParser,
        this will be used. If neither is present, the program name will be used.""")
parser.add_argument('-e', '--extra', help="""Add an additional section at the end of
        the page. All words that are written in all caps at the start of the argument
        will be used as the section title, the remainder is considered its body.

        If the ArgumentParser used by the module itself has an extrasections attribute as
        well, this will be treated as a mapping from titles to contents of additional sections.

        When both are present, content given as arguments will be
        appended at the end, overwriting sections with the same name.""",
        action="append", default=[], type=compile('([A-Z ]+) (.*)', DOTALL).match)
parser.add_argument('-p', '--program', help="""When the program does not
Example #2
0
#!/usr/bin/python
"""Generates a manual page from a module using argparse."""

from argparse import ArgumentParser
from re import compile, DOTALL

# Do not modify ArgumentParser yet. First, it is needed proper for this program itself.

parser = ArgumentParser(
    description="Generates a manpage from an argparse help text.")
parser.short = __doc__
parser.add_argument('module', help="module to generate manpage for")
parser.add_argument('-d',
                    '--short',
                    metavar="DESCRIPTION",
                    help="""
        Specifies a short description to add in the NAME section. This can also be set
        on the ArgumentParser itself by assigning it an attribute 'short'. This will
        be the summary shown by apropos. When not given, this will just consist
        of the executable name. The inherent description text given at ArgumentParser
        construction will always end up in the DESCRIPTION section.""")
parser.add_argument('-s',
                    '--suite',
                    help="""Specifies the suite to insert into the header.
        If not given and the program sets an attribute 'suite' on its ArgumentParser,
        this will be used. If neither is present, the program name will be used."""
                    )
parser.add_argument('-e',
                    '--extra',
                    help="""Add an additional section at the end of
        the page. All words that are written in all caps at the start of the argument