Reputation: 761
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.
Upvotes: 32
Views: 12576
Reputation: 163277
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.
Upvotes: 49