How to make `help` act like` --help` in argparse

I want the help parameter to act just like --help .

sidenote . I created a program with the same command line behavior as svn or hg. I managed to do this with steamers. However, I want to make everything consistent. That is why I want help to work.

+4
source share
2 answers

To create an alias, you can do the following: make program help acts just like program --help

 import argparse def help(args): args.parser.print_help() parser = argparse.ArgumentParser(description='my program') subparsers = parser.add_subparsers() p_help = subparsers.add_parser('help') p_help.set_defaults(func=help, parser=parser) args = parser.parse_args() args.func(args) 
+4
source

It seems to me that you want to define help as another subparameter. I would naively say that you could associate it with the print_help () function to copy the output of your standard --help , but I am wondering if there is a way to call the native help of the function ().

0
source

All Articles