I use the excellent Python Click library to handle command line options in my tool. Here's a simplified version of my code (full script here ):
@click.command( context_settings = dict( help_option_names = ['-h', '--help'] ) ) @click.argument('analysis_dir', type = click.Path(exists=True), nargs = -1, required = True, metavar = "<analysis directory>" ) def mytool(analysis_dir): """ Do stuff """ if __name__ == "__main__": mytool()
If someone runs the command without any flags, they get a default error message:
$ mytool Usage: mytool [OPTIONS] <analysis directory> Error: Missing argument "analysis_dir".
This is good, but I would really like to tell (very) novice users that additional help is available using the help flag. In other words, add the special offer in the error message when the command is not valid so that people try mytool --help for more information.
Is there an easy way to do this? I know that I can remove the required attribute and process this logic in the main function, but it looks like a hack for such a minor addition.
python command-line-arguments python-click
tallphil
source share