autoprogram icon indicating copy to clipboard operation
autoprogram copied to clipboard

Autoprogram with custom Formatter

Open iv3wjr opened this issue 5 years ago • 2 comments

I'm using autoprogram to document a Python script that uses argparse with a custom Formatter class that inherits from argparse.ArgumentDefaultsHelpFormatter and argparse.RawDescriptionHelpFormatter. The RST string returned by the render_rst() function defined in autoprogram.py is not aware of the formatter and therefore the default value (default = xxx) is not added to the help string. I noticed that the parser instance inside the make_rst() method of the AutoprogramDirective class defined in autoprogram.py has a _get_formatter() method that returns the formatter and that the formatter object has a _format_action() method that correctly formats the action. I do not know if this can help in adding this feature to autoprogram.py but your opinion would be very appreciated. Roberto

iv3wjr avatar Apr 03 '20 10:04 iv3wjr

@iv3wjr Can you please post a working example of the problem?

langston-barrett avatar Feb 09 '21 16:02 langston-barrett

sphinx.zip I hope the zip contains all the files needed to reproduce the issue. $ python3 myparser.py -h gives:

usage: the_command [-h] [-o OPTION]

This is the description

optional arguments: -h, --help show this help message and exit -o OPTION, --option OPTION This is the 1st line of the help text for the option Follows the second line And the third. (default: default_value)

But the html generated page looses formatting and the default value:

Screenshot_20210210_105719

iv3wjr avatar Feb 10 '21 09:02 iv3wjr