Question

I am using Sphinx/reStructuredText to create HTML and PDF docs for a project and am including the output of the argparse help for the command line tools. At the moment I am pasting the output in manually but plan at some point to switch to autogenerated output.

The problem is that while the formatting is fine for named parameters (like -x or --xray) it doesn't work well on positional parameters. It looks like the absence of a leading '-' on the parameter name is confusing it. The output looks like normal text without the neat indentation etc.

So my question is, does there exist markup that would force formatting the positional parameters as if they had leading '-' characters? If not, could someone suggest where in the docs or code I should start looking to put something together myself?

Was it helpful?

Solution

You may use sphinx-argparse extension. It does not use output of argparse help, but it instead introspects argparse parser itself and provides proper sphinx markup for both positional arguments and options, formatting them as definition list with proper labels.

Sub-commands are also easily handled.

http://sphinx-argparse.readthedocs.org/en/latest/

It will also cover you needs in:

plan at some point to switch to autogenerated output

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top