'Python argparse: Is there a way to print help for only a specific parameter?

I have a long list of parameters, so the output from mycommand --help is getting very big. I would like to provide my users a way to get the help text for only a specific parameter.

Something like this (doesn't work, shows the whole help text)

mycommand --help --parameter-of-interest

I don't want to split everything into subparsers if at all avoidable.



Solution 1:[1]

This has been discussed here: Customize argparse help message

In essence, you can overwrite the help by adding --help as argument.

Edit: the custom help could be pointing to a syntax for getting help on a specific parameter like -s parameter_you_wish_help_about.

Edit 2: Haven't tested it, but something along this lines.

parser.add_argument('-s',action='store',dest='para', type=str, help='Get Help on specific parameter')
parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS, help='Use -s to get help on specific parameter')

help_dict={}
help_dict['para_1']='Help on para_1'
print (help_dict[args.para])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1