python callables from CLI too !
Project description
cli2: python callables from CLI too !
Install cli2 ie.:
$ pip3 install --user cli2
Cli2 can be used as a generic command line to execute callbacks and print docstrings:
$ cli2 --debug your.callback $ cli2 your.callback arg0 kwarg0=aoeu
, or as a CLI framework: first give it a name in the console_scripts entry point like yourapp and point it to cli2:console_script, example using setupmeta’s entry_points.ini:
[console_scripts] yourapp = cli2:console_script
Then register your commands easily, ie:
[yourapp] # bind yourapp help to cli2.help yourapp help = cli2.help # bind yourapp run to yourapp.cli.run yourapp run = yourapp.cli.run # bind yourapp * to callbacks in yourapp.cli yourapp * = yourapp.cli
Help:
Clitoo makes your python callbacks work on CLI too ! This CLI can execute python callbacks with parameters. Clitoo recognizes 4 types of command line arguments: - lone arguments are passed as args - arguments with = are passed as kwargs - dashed arguments like -f arrive in context.args - dashed arguments like -foo=bar arrive in context.kwargs It doesn't matter how many dashes you put in the front, they are all removed. To use the context in your callback just import the clitoo context:: from clitoo import context print(context.args, context.kwargs) Clitoo provides 2 builtin commands: help and debug. Any other first argument will be considered as the dotted path to the callback to import and execute. Examples: clitoo help your.mod.funcname Print out the function docstring. clitoo debug your.func -a --b --something='to see' how it=parses Dry run of your.mod with arguments, dump out actual calls. clitoo your.mod.funcname with your=args Call your.mod.funcname('with', your='args').
Demo:
$ clitoo debug your.func -a --b --something='to see' how it=parses Could not import your.func nor clitoo.your.func Args: ('how',) Kwargs: {'it': 'parses'} Context args: ['a', 'b'] Context kwargs: {'something': 'to see'}
Fallbacks
Clitoo will attempt to fallback on packages of its own. If it doesn’t find the git.clone callback from the git package, or doesn’t find the git package itself, it will find clitoo.git.clone which is a builtin command that we use in CI.
Making your own command
See the djcli repository for an example of command that is packaged as standalone, but it looks like:
# Declare the following as CLI entry_point def cli(): clitoo.context.default_module = __name__ return clitoo.main()
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
File details
Details for the file cli2-0.0.1.dev72.tar.gz
.
File metadata
- Download URL: cli2-0.0.1.dev72.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11264f18fe58d81b4e280961be0289bf00d2d8a820f78229a947189d54f45691 |
|
MD5 | b7cde40ae8168e36c08799349159db42 |
|
BLAKE2b-256 | 41563fbfdb8b98ed531c565b3fcdffd1349d530500273215c9055e75cf676bb1 |