pyrocko.cli

Command line argument parsing infrastructure for Pyrocko’s tools.

Classes

PyrockoArgumentParser([prog, usage, ...])

Tweaks and extends the standard argument parser to simplify the generation of the online docs.

class PyrockoArgumentParser(prog=None, usage=None, description=None, epilog=None, **kwargs)[source]

Bases: ArgumentParser

Tweaks and extends the standard argument parser to simplify the generation of the online docs.

We want to convert the --help outputs to rst for the html docs. Problem is that argparse’s HelpFormatter to date have no public interface which we could use to achieve this. The solution here is a bit clunky but works ok for our purposes. We allow markup like ``code`` which is kept when producing rst (by parsing the final --help output) but stripped out when doing normal --help. This leads to a problem with the internal output wrapping of argparse which it does before the stripping. To solve, we render with argparse to a very wide width and do the wrapping in post-processing. ``code`` is replaced with just code in normal output. ```code``` is replaced with 'code' in normal output and with ``code`` in rst output. rst output is selected with environment variable PYROCKO_RST_HELP=1. The script maintenance/argparse_help_to_rst.py extracts the rst help and generates the rst files for the docs.