I am creating a Python package with a command-line interface that uses the subcommand pattern: kevlar count
, kevlar partition
, and so on. The CLI works wonderfully as it is, and now I'm trying to add the CLI to my Sphinx documentation. In searching for a solution, I came across sphinxcontrib-autoprogram which seems to do exactly what I want, even explicitly handling subcommands. But when I execute the sphinx build, I get the following error.
sphinx-build -b html -d _build/doctrees . _build/html
Running Sphinx v1.6.3
loading pickled environment... not yet created
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 5 source files that are out of date
updating environment: 5 added, 0 changed, 0 removed
reading sources... [ 20%] cli
usage: sphinx-build [-h] [-v] [-l F] cmd ...
sphinx-build: error: argument cmd: invalid choice: 'html' (choose from 'reaugment', 'dump', 'novel', 'collect', 'mutate', 'assemble', 'filter', 'partition', 'count', 'localize')
make[1]: *** [html] Error 2
make: *** [doc] Error 2
It seems like the sphinx extension is not only creating the argparse object (expected), but is also calling parse_args()
on it (unexpected). The "invalid" html
argument comes from the sphinx command-line build invocation, but is being mistaken somewhere as one of the subcommands from my library's CLI.
My syntax seems to match the sphinxcontrib-autoprogram documentation.
.. autoprogram:: cli:parser
:prog: kevlar
What could be causing this behavior?
I'm not sure if these details are relevant to the issue, but in case they are:
- the parser is defined in
kevlar/cli/__init__.py:parser()
- the subparsers for each command are defined in dedicated files in kevlar/cli/ (for example kevlar/cli/count.py)