Why does my use of click.argument produce "got an unexpected keyword argument 'help'? Why does my use of click.argument produce "got an unexpected keyword argument 'help'? python python

Why does my use of click.argument produce "got an unexpected keyword argument 'help'?


I run into this again and again because the trace output does not correspond to the parameter causing the error. Notice ArgumentClass in the trace, that's your hint.

'help' is an acceptable parameter to @click.option. The click library prefers, however, that you document your own arguments. The @click.argument help parameter is causing this exception.

This code works: (notice the lack of , help="start|stop|restart" in @click.argument)

import click@click.command()@click.argument('command', required=1)@click.option('--debug/--no-debug', default=False, help="Run in foreground")def main(command, debug):    """ COMMAND: start|stop|restart """    print (command)    print (debug)if __name__ == '__main__':        main()

Output:

$ python3 foo.py startstartFalse

Help Output:

Usage: test.py [OPTIONS] COMMAND  COMMAND: start|stop|restartOptions:  --debug / --no-debug  Run in foreground  --help                Show this message and exit.


You are defining commands as arguments. Note that click has a better way to define commands then what you are trying here.

@click.group()def main():    pass@click.command()def start():    print "running command `start`"@click.command()def stop():    print "running command `stop`"main.add_command(start)main.add_command(stop)if __name__ == '__main__':    main()

will result in the following default help text:

Usage: test.py [OPTIONS] COMMAND [ARGS]...Options:  --help  Show this message and exit.Commands:  start  stop

Having said that, should you really need arguments, you cannot use the help parameter. The click documentation indeed states that you should document your own arguments. However, I have no idea how to do that. Any hints?


click library does not allow -help parameter inside click.arguments (including the current version 6.7 when this comment has been written).But, you can use the -help parameter inside click.options.
You can check current click documentation at http://click.pocoo.org/6/documentation/ or previous at http://click.pocoo.org/5/documentation/ this behaviour has not change recently.Then, it is a WAD. It is not a BUG.