I decorate my functions wit @click.command
and @click.option
to give command line access to the function.
But how can I then run the original function?
import click
@click.command("user-info")
@click.option("--name")
def print_user_info(name: str):
print(f"info for {name}")
if __name__ == "__main__":
print_user_info(name="john")
gives a type error:
TypeError: init() got an unexpected keyword argument 'name'
EDIT: A workaround would be to add another function inside of the wrapped function:
def print_user_info(name: str):
print(f"info for {name}")
@click.command("user-info")
@click.option("--name")
def print_user_info_click(name: str):
print_user_info(name=name)