32

I'm using the click package for creating a command line tool. However, I would like to have a 'list' command. For example:

@click.command
@click.option(help='list...')
def list():
    # do stuff here

Is there another way in click to pass in a command name other than having it as the function name? I don't want this function to shadow python's built in list. I've looked through the documentation and can't really find anything about command names -- I've read up on command aliases but that doesn't seem to help this problem. Or do I not need to worry about list being shadowed since it's being wrapped by the click decorator? Thanks in advance.

1 Answer 1

49

You can provide the name argument when you use the command decorator. Once you've done that, you can name your function whatever you want:

@click.command(name='list')
def list_command():
    pass

See the Click documentation for details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.