battalion
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.cfg]
>
> 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]
>
Metadata
Release files for battalion 0.5.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| battalion-0.5.6.tar.gz | 9.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| battalion-0.5.6-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 23.5 kB
Release files / battalion-0.5.6.tar.gz
| Download URL | battalion-0.5.6.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4cec6ceeab9bd2084f2246e7d30e82466347e580c26d02bafa134b7f6e7b0f72
|
|
BLAKE2b-256 checksum How to use checksums |
f80098431d3b9911f16d4d395d09773615b6866ae2b8d2528cef6cef889d5940
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / battalion-0.5.6-py2.py3-none-any.whl
| Download URL | battalion-0.5.6-py2.py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
33c6f58e647ab123781a9843f4728832f61d4d45bf6e67becc3ab8082c0b52be
|
|
BLAKE2b-256 checksum How to use checksums |
70b25d8ee10424c864d88c2a7d6b5399e25806c3dc048b48fd517cf3b1f64fec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for battalion 0.5.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.