Created
June 23, 2022 20:45
-
-
Save nballenger/3ae8d6112543555a9995021eb6be2f70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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