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.1.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for commandapp-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f356872c76cba48fc1c018f66dd6b30e7cc336a5bfc61653516bb5521a0199d6 |
|
MD5 | 2e4e7803db6060fe0294d634cddeba69 |
|
BLAKE2b-256 | 261510728bbe7e71d1746494c30bb2c9864b3e24f780b7adb6943d49e14e5aa6 |