I'm not familiar with argh
, but apparently it is a wrapper to argparse
. My guess is that it is taking your function __doc__
, and making it the description
of a parser, e.g.
parser = argparse.ArgumentParser(description=func.__doc__)
https://docs.python.org/2.7/library/argparse.html#argparse.RawDescriptionHelpFormatter
argparse
has a RawDescriptionHelpFormatter
that displays the description as is.
parser = argparse.ArgumentParser(description=func.__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
So the question is, is there a way of getting argh
to use this formatter?
This argparse
script produces the help that you want:
import argparse
def func(foo=1, bar=True):
"""Sample function.
Parameters:
foo: float
An example argument.
bar: bool
Another argument.
"""
print foo, bar
parser = argparse.ArgumentParser(prog='script.py',
description=func.__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-f', '--foo', type=float)
parser.add_argument('-b', '--bar', action='store_false')
parser.print_help()
In argh/dispatching.py
def dispatch_command(function, *args, **kwargs):
...
parser = argparse.ArgumentParser(formatter_class=PARSER_FORMATTER)
set_default_command(parser, function)
dispatch(parser, *args, **kwargs)
So you could either set:
PARSER_FORMATTER = argparse.RawDescriptionHelpFormatter
or write your own function:
def raw_dispatch_command(function, *args, **kwargs):
...
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
set_default_command(parser, function)
dispatch(parser, *args, **kwargs)