-1

I'm trying to set an option to a function in the click library of python. when I pass the argument to the function and run it, it never works. it says that the option is not defined.

here is the whole code:

mport sys
import paramiko as pk
import click

@click.group
def my_commands():
    pass
    


@click.command()
@click.option("--host", prompt="enter the host ip", required=True, help="the host ip", type=str)
@click.option("--user", prompt="enter the user (default:root)", required=True, default='root',help="the user  the you want to search for, default=root", type=str)
#@click.password_option()
def connect(host,user): 

 click.echo("hello world!")

my_commands.add_command(connect)

if __name__ == "__main__":
    my_commands()

this is the way I set the cli and the error:

$ ./main.py --host='10.0.0.25' --user='pi'

Usage: main.py [OPTIONS] COMMAND [ARGS]...

Try 'main.py --help' for help.

Error: No such option: --host

I was expecting for this to work normally but for some reason it's not.

hope someone can help me.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

0 Answers0