Last active
March 3, 2017 19:12
-
-
Save msanders/2c9dbf5c953e80217749 to your computer and use it in GitHub Desktop.
Optional argument in click
This file contains 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
import click | |
def set_global_domain(ctx, param, value): | |
if value: | |
ctx.params["domain"] = "NSGlobalDomain" | |
return value | |
@click.group() | |
def cli(): | |
pass | |
@cli.command("set-default") | |
@click.option("-g", "--globalDomain", is_flag=True, callback=set_global_domain) | |
@click.argument("domain", required=False) | |
@click.argument("key") | |
@click.argument("value") | |
def set_default(domain, key, value, globaldomain=None): | |
print((domain, key, value)) | |
def main(): | |
cli() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment