k3shell
A python module to manage commands.
k3shell is a component of pykit3 project: a python3 toolkit set.
Name
k3shell
Status
The library is considered production ready.
Install
pip install k3shell
Synopsis
import sys
import k3shell
arguments = {
"echo_repr": (
lambda x: sys.stdout.write(repr(x)),
("x", {"nargs": "+", "help": "just an input message"}),
),
"foo": {
"bar": lambda: sys.stdout.write("bar"),
"bob": {
"plus": (
lambda x, y: sys.stdout.write(str(x + y)),
("x", {"type": int, help: "an int is needed"}),
("y", {"type": int, help: "an int is needed"}),
),
},
},
"__add_help__": {
("echo_repr",): "output what is input.",
(
"foo",
"bar",
): 'print a "bar".',
(
"foo",
"bob",
"plus",
): "do addition operation with 2 numbers.",
},
"__description__": "this is an example command.",
}
k3shell.command(**arguments)
"""
then you can execute your command as:
python demo.py echo_repr hello!
# 'hello!'
python demo.py foo bar
# 'bar'
python demo.py foo bob plus 1 2
# 3
and you can get a usage help message like:
$ python demo.py -h
---------------------------
usage: demo.py [-h] {echo_repr, foo bar, foo bob plus} ...
this is an example command.
positional arguments:
{echo_repr, foo bar, foo bob plus} commands to select ...
echo_repr output what is input.
foo bar print a "bar".
foo bob plus do addition operation with 2 numbers.
optional arguments:
-h, --help show this help message and exit
$ python demo.py foo bob plus -h
--------------------------
usage: demo.py foo bob plus [-h] x y
positional arguments:
x an int is need
y an int is need
optional arguments:
-h, --help show this help message and exit
"""
Author
Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Metadata
Release files for k3shell 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| k3shell-0.1.7.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k3shell-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / k3shell-0.1.7.tar.gz
| Download URL | k3shell-0.1.7.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df84019f9d4004b7f17c4883d298807aa793c47e090cce5a65a5e6d8343cc3fd
|
|
BLAKE2b-256 checksum How to use checksums |
dc0aafa359c7437e0950c96e1e63507e8f05745e3256c3fb2e005946b78f5f83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / k3shell-0.1.7-py3-none-any.whl
| Download URL | k3shell-0.1.7-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c296eba0f9ac056146e5f969cc7e1343e4f4289d63d9db227c5321d38375990
|
|
BLAKE2b-256 checksum How to use checksums |
e5bd40768d5db623baf393b85011678444ef71895a3c5c9d98ee35a9a4c79cd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|