Skip to main content

Build CLI Tools with ease

Project description

pyclilib

Python Library to create CLI tools using Subject-Verb-Object pattern

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.get
    def get(self):
        print "Hello world"

clilib.run("mycli")
  1. Run your program
$ python example.py get my-resource
Hello world

Quickstart 1: CLI with Namespaces

  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

Testing

  • flake8
  • pytest
  • pylogrus

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.2.0.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

pyclilib-0.2.0-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

Supported by

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