Skip to main content

Simple framework for building scalable CLI tool

Project description

uroboros

Build Status PyPI pyversions PyPI version shields.io GitHub license

Simple framework for building scalable CLI tool.

NOTE
This framework currently under development. Please be careful to use.

Features

  • Simple interface
  • Pure python
    • Thin wrapper of argparse
    • No third party dependencies
  • Easy to reuse common options
  • Easy to create sub commands
    • Nested sub command is also supported

Environment

  • Python >= 3.5
    • No support for python 2.x

Install uroboros

$ pip install uroboros

How to use

Implement your command using uroboros.Command and create a command tree.

# sample.py
from uroboros import Command
from uroboros.constants import ExitStatus

class RootCommand(Command):
    """Root command of your application"""
    name = 'sample'
    long_description = 'This is a sample command using uroboros'

    def build_option(self, parser):
        """Add optional arguments"""
        parser.add_argument('--version', action='store_true', default=False, help='Print version')
        return parser

    def run(self, args):
        """Your own script to run"""
        if args.version:
            print("{name} v{version}".format(
                name=self.name, version='1.0.0'))
        else:
            self.print_help()
        return ExitStatus.SUCCESS

class HelloCommand(Command):
    """Sub command of root"""
    name = 'hello'
    short_description = 'Hello world!'
    long_description = 'Print "Hello world!" to stdout'

    def run(self, args):
        print(self.short_description)
        return ExitStatus.SUCCESS

# Create command tree
root_cmd = RootCommand()
root_cmd.add_command(HelloCommand())

if __name__ == '__main__':
    exit(root_cmd.execute())

Then, your command works completely.

$ python sample.py -h
usage: sample [-h] [--version] {hello} ...

This is a sample command using uroboros

optional arguments:
  -h, --help  show this help message and exit
  --version   Print version

Sub commands:
  {hello}
    hello     Hello world!
$ python sample.py --version
sample v1.0.0
$ python sample.py hello
Hello world!

If you want to use new sub command sample.py hello xxxx, you just implement new XXXXCommand and add it to Hello.

root_cmd = RootCommand().add_command(
    HelloCommand().add_command(
        XXXXCommand()
    )
)

You can see other examples in examples.

Develop

First, clone this repository and install uroboros with editable option.

$ git clone https://github.com/pddg/uroboros
$ cd /path/to/uroboros
$ pip install -e .

Use Pipenv for lint and test.

# Create environment
$ pipenv install --dev
# Execute lint by flake8
$ pipenv run lint
# Execute test by py.test
$ pipenv run test

Also support test with tox. Before execute test with tox, you should make available to use python 3.5 and 3.6, 3.7.

License

Apache 2.0

Author

Shoma Kokuryo

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

uroboros-0.2.3.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

uroboros-0.2.3-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file uroboros-0.2.3.tar.gz.

File metadata

  • Download URL: uroboros-0.2.3.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for uroboros-0.2.3.tar.gz
Algorithm Hash digest
SHA256 48d400ff0475683a33b6b4f31b9c6325bdef716e01db45918e793c0ad3f0375e
MD5 3832efd1818bda9b85e77c537151168b
BLAKE2b-256 22c0a8eb03a5009b576cd1cc4274a6e93639c74c08eef2b4edf264b6f5a4b4f8

See more details on using hashes here.

File details

Details for the file uroboros-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: uroboros-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for uroboros-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3e97e88d260af7a7f7dfaeb13665b0d7f3e7650aa216063a393aab35e9d43486
MD5 07a1ae8f093ea66c38ec84915f4bdced
BLAKE2b-256 009b5adb3a21bf59f7071292d4ca1b248b711df8633ed4fee5972cc0f81838c7

See more details on using hashes here.

Supported by

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