library to create a commandline application easily
Project description
PyCommandApp
library to create a commandline application easily
Index
Installation
python3 -m pip install commandapp
View on pypi.org
Usage
Code
from commandapp import CommandApp
app = CommandApp()
@app.register
def hello(name: str):
r"""
prints hello `name`
"""
print("Hello {}".format(name))
@app.register(name="print")
def cmd_print(text: str):
r"""
print what he should say
"""
print(text)
app.run()
Console
>> py myapp.py
usage: -c [-h] {hello,print} ...
>> py myapp.py -h
usage: -c [-h] {hello,print} ...
optional arguments:
-h, --help show this help message and exit
command:
{hello,print} available commands
hello prints hello `name`
print print what he should say
>> py myapp.py hello
usage: -c hello [-h] name
hello: error: the following arguments are required: name
>> py myapp.py hello "python"
Hello python
>> py myapp.py print "This package is awesome"
This package is awesome
Tips
Keyword-Parameter
Code
from commandapp import CommandApp
app = CommandApp()
@app.register
def a(param: str):
print([param])
@app.register
def b(*, param: str):
print([param])
app.run()
Console
>> py myapp.py a "Value"
["Value"]
>> py myapp.py b "Value"
b: error: the following arguments are required: --param
>> py myapp.py b --param "Value"
["Value"]
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
commandapp-0.2.0.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for commandapp-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63fac2f904c683f389ca727046af2760bb60b8e7f4c620f3d46ff5d27554b467 |
|
MD5 | 8f852c76cbdcfce814753af34708492a |
|
BLAKE2b-256 | 6cfb8594abac207a95d753a682c74e8a876f8d0196924dc619780d423fca716e |