|
5 | 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html |
6 | 6 |
|
7 | 7 | import datetime |
| 8 | +import textwrap |
8 | 9 |
|
9 | 10 | # -- Path setup -------------------------------------------------------------- |
10 | 11 |
|
@@ -110,4 +111,40 @@ def linkcode_resolve(domain, info): |
110 | 111 | # 1. sphinx-mv/main.py know current version of the library by git tag, |
111 | 112 | # but conf.py has no way to know that... |
112 | 113 | # 2. target-versions.csv file can be read once and used in the for loop |
113 | | -# in sphinx-mv/main.py, but here it should be read in for each `docs` bulid. |
| 114 | +# ... (previous content) |
| 115 | + |
| 116 | +def generate_cli_rst(app): |
| 117 | + import mmif |
| 118 | + from mmif import prep_argparser_and_subcmds, find_all_modules |
| 119 | + |
| 120 | + # Generate main help |
| 121 | + os.environ['COLUMNS'] = '100' |
| 122 | + parser, subparsers = prep_argparser_and_subcmds() |
| 123 | + help_text = parser.format_help() |
| 124 | + |
| 125 | + content = [] |
| 126 | + |
| 127 | + content.append('Main Command\n') |
| 128 | + content.append('------------\n\n') |
| 129 | + content.append('.. code-block:: text\n\n') |
| 130 | + content.append(textwrap.indent(help_text, ' ')) |
| 131 | + content.append('\n\n') |
| 132 | + |
| 133 | + # Generate subcommand help |
| 134 | + for cli_module in find_all_modules('mmif.utils.cli'): |
| 135 | + cli_module_name = cli_module.__name__.rsplit('.')[-1] |
| 136 | + subparser = cli_module.prep_argparser(prog=f'mmif {cli_module_name}') |
| 137 | + sub_help = subparser.format_help() |
| 138 | + |
| 139 | + content.append(f'{cli_module_name}\n') |
| 140 | + content.append('-' * len(cli_module_name) + '\n\n') |
| 141 | + content.append('.. code-block:: text\n\n') |
| 142 | + content.append(textwrap.indent(sub_help, ' ')) |
| 143 | + content.append('\n\n') |
| 144 | + |
| 145 | + with open(proj_root_dir / 'documentation' / 'cli_help.rst', 'w') as f: |
| 146 | + f.write(''.join(content)) |
| 147 | + |
| 148 | + |
| 149 | +def setup(app): |
| 150 | + app.connect('builder-inited', generate_cli_rst) |
0 commit comments