Python framework for commandline applications
Project description
Python framework for commandline applications
Quickstart
Feeling impatient? I like your style.
$ pip install battalion
In mycli.py script:
from battalion.api import *
class DB(object):
def __init__(self, state):
self.msg = state.msg
def myfunc(self):
return self.msg
@fixture
def db(state):
return DB(state)
class mycli(CLI):
"""
Toplevel program - mycli
"""
class State:
version = '0.0.1'
msg = ""
@command
def normal_function(cli, db, data=None): # NOTE: the "db" arg will be populated from the "db" fixture function
"""Takes in data and outputs new data"""
if data is None:
return db.myfunc()
else:
return data
@command
def greeting(cli, name="Hello"):
"""
Prints "Hello {name}!"
"""
print "Hello {0}!".format(name)
class myhandler(Handler):
"""
Organizational container of commands which can also add state variables
"""
class State:
version = '0.0.2' # Handlers can have their own versioning
cli = 'mycli'
msg = "World"
@command
def validate(cli, data):
return data
@command
def hello(cli, msg=None):
"""
Prints "Hello World!"
"""
name = cli.normal_function(data=msg)
name = cli.myhandler.validate(data=name)
cli.greeting(name=name)
if __name__ == "__main__":
mycli.main()
Then on the commandline
$ python mycli.py myhandler hello
> Hello World!
$ #or if installed as a console script via setuptools
$ mycli myhandler hello
> Hello World!
$ #also
$ mycli myhandler hello "Josh"
> Hello Josh!
$ mycli --help
> Toplevel program - mycli
>
> Usage:
> mycli [options] <command> [<args>...]
> mycli [options]
>
> Options:
> -h, --help Show this screen.
> --version Show version.
> -d, --debug Show debug messages
> --config=<CONFIG> The config filepath [default: ~/.mycli/mycli.yaml]
>
> Commands:
> greeting Prints "Hello {name}!"
> myhandler Organizational container of commands which can also add state variables
>
$ mycli myhandler hello --help
> Prints "Hello World!"
>
> Usage:
> hello [options]
> hello <msg>
>
> Options:
> --msg=<MSG> [default: None]
>
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
battalion-0.2.0.tar.gz
(19.9 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 battalion-0.2.0.tar.gz.
File metadata
- Download URL: battalion-0.2.0.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
855bab5ac3e04f11cb15d7d951e2524f24b21913fa4a7fc99454fb50bbba013b
|
|
| MD5 |
15302b88e12ab9a35fed53c85de46d36
|
|
| BLAKE2b-256 |
cb714a64231c0e5997789cd181d378da595b86627002b3c1f8c51cdc6537cc97
|
File details
Details for the file battalion-0.2.0-py2.py3-none-any.whl.
File metadata
- Download URL: battalion-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b74380255582389dfe9e43a5c113f5bb20d05fcb01ee7dca70e9c2929843cc3d
|
|
| MD5 |
6c6efbc552fb7d4627b11b5fe93bb12b
|
|
| BLAKE2b-256 |
3cdd0ac2199377913d7dcdd151c87b3aececdb8cd0f35c278563a4b01175f1d9
|