DevC DevC - 1 year ago 117
Python Question

click no such command found

I am trying click (Command line interface package for Python), while running the following code I get error

Error: No such command "abcd"
@click.option('--source', required=True)
def cli(ctx, source):
ctx.obj = "pass it"

def hello(ctx, abcd):
click.echo("Hello, World")

if __name__ == '__main__':

I am running it as follows

python --source this abcd

Answer Source

"abcd" is being treated as a separate command because of the space (this is a characteristic of your shell, not of click specifically).

If you want the value of source to be "this abcd", use quotes:

python --source "this abcd"

To actually provide the abcd argument, you need to call the hello command – the argument is for that command:

python --source this hello 123456

The hello command will have an argument of 123456.

Breaking down the entire line:

--source this provides the source argument to the main cli command. hello is the command to run (try python --source this and you'll get an error because there is no command), and 123456 is the argument named abcd to that command.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download