I want to use some useful functions as commands. For that I am testing the click
library. I defined my three original functions then decorated as click.co
Due to the click decorators the functions can no longer be called just by specifying the arguments. The Context class is your friend here, specifically:
So your code for add_name_and_surname should look like:
@click.command()
@click.argument('content', required=False)
@click.option('--to_stdout', default=False)
@click.pass_context
def add_name_and_surname(ctx, content, to_stdout=False):
result = ctx.invoke(add_surname, content=ctx.forward(add_name))
if to_stdout is True:
sys.stdout.writelines(result)
return result
Reference: http://click.pocoo.org/6/advanced/#invoking-other-commands