sphinx-build: Move parser to a separate function

This should be becoming passe at this point.

Signed-off-by: Stephen Finucane <stephen@that.guru>
This commit is contained in:
Stephen Finucane 2017-09-28 20:10:32 +01:00
parent b778cfe299
commit aedeb2160a

View File

@ -83,11 +83,27 @@ def handle_exception(app, args, exception, stderr=sys.stderr):
file=stderr) file=stderr)
def main(argv=sys.argv[1:]): # type: ignore def get_parser():
# type: (List[unicode]) -> int # type: () -> argparse.ArgumentParser
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
usage='usage: %(prog)s [OPTIONS] SOURCEDIR OUTDIR [FILENAMES...]', usage='usage: %(prog)s [OPTIONS] SOURCEDIR OUTPUTDIR [FILENAMES...]',
epilog='For more information, visit <http://sphinx-doc.org/>.') epilog='For more information, visit <http://sphinx-doc.org/>.',
description="""
Generate documentation from source files.
sphinx-build generates documentation from the files in SOURCEDIR and places it
in OUTPUTDIR. It looks for 'conf.py' in SOURCEDIR for the configuration
settings. The 'sphinx-quickstart' tool may be used to generate template files,
including 'conf.py'
sphinx-build can create documentation in different formats. A format is
selected by specifying the builder name on the command line; it defaults to
HTML. Builders can also perform other tasks related to documentation
processing.
By default, everything that is outdated is built. Output only for selected
files can be built by specifying individual filenames.
""")
parser.add_argument('--version', action='version', dest='show_version', parser.add_argument('--version', action='version', dest='show_version',
version='%%(prog)s %s' % __display_version__) version='%%(prog)s %s' % __display_version__)
@ -112,7 +128,7 @@ def main(argv=sys.argv[1:]): # type: ignore
'all files') 'all files')
group.add_argument('-d', metavar='PATH', dest='doctreedir', group.add_argument('-d', metavar='PATH', dest='doctreedir',
help='path for the cached environment and doctree ' help='path for the cached environment and doctree '
'files (default: outdir/.doctrees)') 'files (default: OUTPUTDIR/.doctrees)')
group.add_argument('-j', metavar='N', default=1, type=int, dest='jobs', group.add_argument('-j', metavar='N', default=1, type=int, dest='jobs',
help='build in parallel with N processes where ' help='build in parallel with N processes where '
'possible') 'possible')
@ -120,7 +136,7 @@ def main(argv=sys.argv[1:]): # type: ignore
group = parser.add_argument_group('build configuration options') group = parser.add_argument_group('build configuration options')
group.add_argument('-c', metavar='PATH', dest='confdir', group.add_argument('-c', metavar='PATH', dest='confdir',
help='path where configuration file (conf.py) is ' help='path where configuration file (conf.py) is '
'located (default: same as sourcedir)') 'located (default: same as SOURCEDIR)')
group.add_argument('-C', action='store_true', dest='noconfig', group.add_argument('-C', action='store_true', dest='noconfig',
help='use no config file at all, only -D options') help='use no config file at all, only -D options')
group.add_argument('-D', metavar='setting=value', action='append', group.add_argument('-D', metavar='setting=value', action='append',
@ -159,6 +175,13 @@ def main(argv=sys.argv[1:]): # type: ignore
group.add_argument('-P', action='store_true', dest='pdb', group.add_argument('-P', action='store_true', dest='pdb',
help='run Pdb on exception') help='run Pdb on exception')
return parser
def main(argv=sys.argv[1:]): # type: ignore
# type: (List[unicode]) -> int
parser = get_parser()
# parse options # parse options
try: try:
args = parser.parse_args(argv) args = parser.parse_args(argv)