Skip to main content

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

  1. pip install pyclilib
  2. 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")
  1. Run your program
$ python example.py get my-resource
Hello world

Quickstart 2: CLI with args

  1. pip install pyclilib
  2. 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")
  1. 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)

  1. pip install clilib
  2. Create the runner, example.py
import clilib

clilib.init("mycli")
clilib.run("mycli")
  1. Namespaces are sub-packages of an expected local namespace package
$ 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")
  1. Run your program
$ python example.py my-namespace get my-resource
Hello World

Notes

  • You can either have cli namespace action resource OR cli action resource in 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 with clilib._log_level = logging.DEBUG

Project details


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyclilib-0.3.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

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

Hashes for pyclilib-0.3.1.tar.gz
Algorithm Hash digest
SHA256 4cff951f9ec3f99d71fe0ca744dce2b3e3e2ae69c76bbe3afba08b33b66a5078
MD5 31f8bf7dee37cce577a5e82b786ad6c1
BLAKE2b-256 6eece679c9fd73a81d27b3540841ab03c0c0527be90d60d43dbe3112a89599bb

See more details on using hashes here.

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

Hashes for pyclilib-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c4a350103a9741ea31d14d2e78c140386ad5ffc6c157ba613f302e7c7f950af5
MD5 11d78c919968c20b45e65b5205a459fb
BLAKE2b-256 1a30ed8aed8f391c1c60337363d8c0569edb91ee55ab7c5e285a92660841936f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page