collection of click extensions
Project description
click-plus
Introduction
This is a curated collection of click extensions.
- click.plus.extension
- supports creation of shareable, pre-configured groups of click arguments/options.
click.plus.extension example
This click-plus package allows creation of common groups of click actions/options amongst scritps.
Let's say we have a set of (fictional) scripts needing a common input int argument (value) a flag (--boost) to multiply the value with; moreover the value*boost should be multiplied by a factor parameter script depended. This is what the scripts look like:
$> by-two.py --boost 3 9
54 (eg. value=9 * boost=3 * factor=2)
$> by-ten.py --boost 4 2
80 (eg. value=2 * boost=4 * factor=10)
The body of by-two.py/by-ten.py looks like:
import click
import click.plus.extension
import my_common_args
@click.command()
@click.argument("value", type=int)
@click.plus.extension.configure(["myarguments"], factor=2)
def main(value):
print("Got", value)
if __name__ == "__main__":
main()
NOTE: in the by-ten.py just replace the factor=2 with factor=10
The my_common_args.py module contains the "myarguments" definition:
import click
from click.plus.extension import api
class MyArguments(api.ExtensionBase):
NAME = "myarguments"
# here you can add as many click arguments/options
def setup(self, fn, arguments):
fn = click.option("--boost", type=int, default=1)(fn)
return fn
# kwargs contains the main **kwargs, you can modify in place
# or return a new dict here. arguments is a dict to the
# decorator arguments
def process(self, kwargs, arguments):
value = kwargs["value"]
boost = kwargs.pop("boost")
factor = arguments["factor"]
kwargs["value"] = value * boost * factor
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
click-plus-0.0.1b22.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for click_plus-0.0.1b22-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e87551fc5c05fd85b986a4f4ca5cb6888e6d620fcacb290286c76504e69ca6de |
|
MD5 | 98e8646b950e889dbd8c212c14e1c98c |
|
BLAKE2b-256 | 20a99563f576afb6ba7996f0f2173439b37c4982f1db655dcfa71660a17ac976 |