python-click

How can I split my Click commands, each with a set of sub-commands, into multiple files?

回眸只為那壹抹淺笑 提交于 2019-11-29 20:23:53
I have one large click application that I've developed, but navigating through the different commands/subcommands is getting rough. How do I organize my commands into separate files? Is it possible to organize commands and their subcommands into separate classes? Here's an example of how I would like to separate it: init import click @click.group() @click.version_option() def cli(): pass #Entry Point command_cloudflare.py @cli.group() @click.pass_context def cloudflare(ctx): pass @cloudflare.group('zone') def cloudflare_zone(): pass @cloudflare_zone.command('add') @click.option('--jumpstart',

Python Click - Supply arguments and options from a configuration file

孤人 提交于 2019-11-29 13:16:46
问题 Given the following program: #!/usr/bin/env python import click @click.command() @click.argument("arg") @click.option("--opt") @click.option("--config_file", type=click.Path()) def main(arg, opt, config_file): print("arg: {}".format(arg)) print("opt: {}".format(opt)) print("config_file: {}".format(config_file)) return if __name__ == "__main__": main() I can run it with the arguments and options provided through command line. $ ./click_test.py my_arg --config_file my_config_file arg: my_arg

Click Command Line Interfaces: Make options required if other optional option is unset

时光总嘲笑我的痴心妄想 提交于 2019-11-28 23:46:11
When writing a command-line interface (CLI) with the Python click library , is it possible to define e.g. three options where the second and third one are only required if the first (optional) one was left unset? My use case is a log-in system which allows me to authenticate either via an authentication token (option 1), or, alternatively, via username (option 2) and password (option 3). If the token was given, there is no need to check for username and password being defined or prompting them. Otherwise, if the token was omitted then username and password become required and must be given.

nargs=* equivalent for options in Click

瘦欲@ 提交于 2019-11-27 23:53:14
Is there an equivalent to argparse 's nargs='*' functionality for optional arguments in Click? I am writing a command line script, and one of the options needs to be able to take an unlimited number of arguments, like: foo --users alice bob charlie --bar baz So users would be ['alice', 'bob', 'charlie'] and bar would be 'baz' . In argparse , I can specify multiple optional arguments to collect all of the arguments that follow them by setting nargs='*' . >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--users', nargs='*') >>> parser.add_argument('--bar') >>> parser.parse_args('-

Add unspecified options to cli command using python-click

痴心易碎 提交于 2019-11-27 09:29:57
I would like to add unspecified options to the cli command using python-click library. So my cli function could look like the following $ my-cmd --option1 value1 --options2 value2 --unknown_var value3 My current code: import click @click.option('--option1') @click.option('--option2') @click.command(name='my-cmd') def cli(option1, option2): click.echo("my test") I would like to see something like the following: import click @click.option('--option1') @click.option('--option2') @click.command(name='my-cmd') def cli(option1, option2, **kwargs): click.echo("my test") # Manually manage **kwargs r-m

Add unspecified options to cli command using python-click

余生颓废 提交于 2019-11-26 17:50:42
问题 I would like to add unspecified options to the cli command using python-click library. So my cli function could look like the following $ my-cmd --option1 value1 --options2 value2 --unknown_var value3 My current code: import click @click.option('--option1') @click.option('--option2') @click.command(name='my-cmd') def cli(option1, option2): click.echo("my test") I would like to see something like the following: import click @click.option('--option1') @click.option('--option2') @click.command

nargs=* equivalent for options in Click

大兔子大兔子 提交于 2019-11-26 14:36:22
问题 Is there an equivalent to argparse 's nargs='*' functionality for optional arguments in Click? I am writing a command line script, and one of the options needs to be able to take an unlimited number of arguments, like: foo --users alice bob charlie --bar baz So users would be ['alice', 'bob', 'charlie'] and bar would be 'baz' . In argparse, I can specify multiple optional arguments to collect all of the arguments that follow them by setting nargs='*' . >>> parser = argparse.ArgumentParser() >