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.
Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It's the “Command Line Interface Creation Kit”. It's highly configurable but comes with sensible defaults out of the box.
When a Click command callback is executed, it's passed all the non-hidden parameters as keyword arguments. Notably absent is the context. However, a callback can opt into being passed to the context object by marking itself with pass_context() .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With