Human friendly CLI builder
Project description
Human friendly CLI builder.
Installation
pip install manage.py
Quickstart
cat manage.py
from manager import Manager
manager = Manager()
@manager.command
def echo(text, capitalyze=False):
"""print the given <name>"""
if capitalyze:
text = text.upper()
return text
if __name__ == '__main__':
manager.main()
manage --help:
usage: manage [<namespace>.]<command> [<args>] positional arguments: command the command to run optional arguments: -h, --help show this help message and exit available commands: echo print the given <name>
manage echo --help:
$ manage echo --help usage: manage [-h] [--capitalyze] text print the given <name> positional arguments: text no description optional arguments: -h, --help show this help message and exit --capitalyze no description
Managers
Managers can be used together by merging them
from third_party import manager
my_app_manager.merge(manager)
# Merge within a new namespace:
my_app_manager.merge(manager, namespace='third_party')
Commands
Commands can be organized within namespaces
@manager.command(namespace='config')
def set(key, value):
# ...
Arguments
Currently the framework will assume that arguments with default values are key-value arguments (--arg value) while required arguments are positional ones.
In other words, this definition:
@manager.command
def create(user):
pass
will expect an invocation of the kind:
$ manage create foobar
and user in create() will take the value 'foobar'.
On the other hand, this:
@manager.command
def create(user=''):
pass
will expect an invocation of the kind:
$ manage create --user foobar
The downside is obviously that it’s not currently possible to have a required non-positional argument.
Argument definition can be overridden
@manager.arg('first_arg', help='this is help for first arg')
@manager.command
def my_command(first_arg):
# ...
Arguments can be prompted
@manager.prompt('password', hidden=True, confirm=True)
@manager.command
def connect(username, password):
# ...
Environment
Environment variables can be sourced from a .env file as key=value pair.
Environment variable can be enforce using Manager.env decorator
@manager.env('MY_ENV_VAR')
@manager.command
def my_command():
return os.environ['MY_ENV_VAR']
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 manage.py-0.2.7.tar.gz
.
File metadata
- Download URL: manage.py-0.2.7.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dce5f86e60a7b051739cc6e06f1e972efc4ea7f91c5e6b8715886a0336e836b |
|
MD5 | 84a3097bbd2ec4afd3b08bc307d60c1d |
|
BLAKE2b-256 | 9775d09563cba454a297f397bce5984fb937bdbe0d96978049b2cbca36b899d2 |