Build CLI Tools with ease
Project description
pyclilib
Python Library to create CLI tools using Subject-Verb-Object pattern
# [my-namespace] not yet implemented
my-cmd [my-namespace] my-action my-resource [pos_args] [--options]
Quickstart 1: CLI without Namespaces
pip install pyclilib- Create a hello world CLI
import clilib
@clilib.decorator.resource
class MyResource():
@clilib.decorator.verb
def get(self):
print("Hello world")
clilib.init("mycli")
clilib.run("mycli")
- Run your program
$ python example.py get my-resource
Hello world
Quickstart 2: CLI with args
pip install pyclilib- Create a hello world CLI with args.
import clilib
# Under the hood, clilib uses argparse.
# the @arg decorator uses its "add_argument" method
@clilib.decorator.resource
@clilib.decorator.arg("--environment", "-e", type=str, default="dev")
class MyResource():
@clilib.decorator.verb
@clilib.decorator.arg("name", type=str)
def get(self, args):
print(f"Get: {args.name}, {args.environment}")
@clilib.decorator.verb
def list(self, args):
print(f"List: {args.environment}")
clilib.init("mycli")
clilib.run("mycli")
- Run your program
$ python example.py get my-resource Foo -e stage
Get: Foo, stage
$ python example.py list my-resource
List: dev
Quickstart 3: CLI with Namespaces (not implemented yet)
pip install clilib- Create the runner,
example.py
import clilib
clilib.init("mycli")
clilib.run("mycli")
- Namespaces are sub-packages of an expected local
namespacepackage
$ mkdir -p namespace namespace/my-namespace
$ touch namespace/__init__.py namespace/my-namespace/__init__.py
# namespace/my-namespace/__init__.py
import clilib
@clilib.decorator.resource
class MyResource():
@clilib.decorator.verb
def get(self):
print("Hello World")
- Run your program
$ python example.py my-namespace get my-resource
Hello World
Notes
- You can either have
cli namespace action resourceORcli action resourcein the future
Roadmap
- Global Config -- Potential
- Namespace
- Conditional Args
- CLI without resource ex.
git init
TODO
- How to make log level configurable?
Since decorators run during "compile"(?) time, setting the level through
clilib.run("foo", logging.DEBUG)will set the level after the decorators do their thing. Same story withclilib._log_level = logging.DEBUG
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
pyclilib-0.3.1.tar.gz
(5.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyclilib-0.3.1.tar.gz.
File metadata
- Download URL: pyclilib-0.3.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cff951f9ec3f99d71fe0ca744dce2b3e3e2ae69c76bbe3afba08b33b66a5078
|
|
| MD5 |
31f8bf7dee37cce577a5e82b786ad6c1
|
|
| BLAKE2b-256 |
6eece679c9fd73a81d27b3540841ab03c0c0527be90d60d43dbe3112a89599bb
|
File details
Details for the file pyclilib-0.3.1-py3-none-any.whl.
File metadata
- Download URL: pyclilib-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4a350103a9741ea31d14d2e78c140386ad5ffc6c157ba613f302e7c7f950af5
|
|
| MD5 |
11d78c919968c20b45e65b5205a459fb
|
|
| BLAKE2b-256 |
1a30ed8aed8f391c1c60337363d8c0569edb91ee55ab7c5e285a92660841936f
|