Skip to content

Instantly share code, notes, and snippets.

@nballenger
Created June 23, 2022 20:45
Show Gist options
  • Save nballenger/3ae8d6112543555a9995021eb6be2f70 to your computer and use it in GitHub Desktop.
Save nballenger/3ae8d6112543555a9995021eb6be2f70 to your computer and use it in GitHub Desktop.
#!/bin/bash
mkdir click_cmd_as_fn
cd click_cmd_as_fn
pipenv install click
touch my_click_cmd.py module_calling_the_click_cmd.py
chmod 755 my_click_cmd.py module_calling_the_click_cmd.py
#!/usr/bin/env python3
import click
from my_click_cmd import do_the_thing
@click.command()
@click.option("--alpha", default="Alfred")
@click.option("--bravo", default="Bob")
@click.pass_context
def call_do_the_thing(ctx, alpha, bravo):
ctx.forward(do_the_thing)
click.echo("-------------------")
ctx.invoke(do_the_thing, alpha="Aubergine", bravo="Baby")
if __name__ == '__main__':
call_do_the_thing()
#!/usr/bin/env python3
import click
@click.command()
@click.option("--alpha", default="apple")
@click.option("--bravo", default="banana")
def do_the_thing(alpha, bravo):
click.echo(f"alpha was: {alpha}")
click.echo(f"bravo was: {bravo}")
if __name__ == '__main__':
do_the_thing()
pipenv run ./module_calling_the_click_cmd.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment