26

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.

user5004049
  • 691
  • 1
  • 8
  • 17

1 Answers1

43

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.

l0b0
  • 55,365
  • 30
  • 138
  • 223
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467