I'm trying to use the Click library in Python to create a command line interface, but I keep getting the following error when I try to run my script:
Error: Got unexpected extra arguments (hello hello1)
Here is my code:
import click
@click.group(name='script')
def cli():
pass
@cli.command()
def hello1():
click.echo('Hello, World!')
@cli.command()
def hello2():
click.echo('Hola, Mundo!')
@cli.command()
@click.argument('function', type=click.Choice(['hello1', 'hello2']))
def hello(function):
if function == 'hello1':
hello1()
elif function == 'hello2':
hello2()
if __name__ == '__main__':
cli()
I'm trying to call the "hello" function with the argument "hello1" or "hello2", but it's not working. Can anyone help me figure out what's going wrong?
python script.py hello hello1