As mentioned in the docs the optparse.OptionParser
uses an IndentedHelpFormatter
to output the formatted option help, for which which I found some API
I'd be interested in a clean solution to this; I wasn't able to come up with one. The OptionParser really focuses entirely on the options; it doesn't give you anything to work with position args, as far as I've been able to find.
What I did was to generate a list of little documentation blocks for each of my positional arguments, using \t
s to get the right spacing. Then I joined them with newlines, and appended that to the 'usage' string that gets passed to the OptionParser.
It looks fine, but it feels silly, and of course that documentation ends up appearing above the list of options. I haven't found any way around that, or how to do any complex stuff, i.e. a given set of options is described beneath the description for a positional arg, because they only apply to that arg.
I looked at monkey-patching OptionParser's methods and I remember (this was a year or so ago) that it wouldn't have been that difficult, but I didn't want to go down that path.