A python module to manage commands.
Project description
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 k3shell
import sys
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
Wenbo Li(李文博) wenbo.li@baishancloud.com
Copyright and License
The MIT License (MIT)
Copyright (c) 2017 Wenbo Li(李文博) wenbo.li@baishancloud.com
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
k3shell-0.1.0.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file k3shell-0.1.0.tar.gz
.
File metadata
- Download URL: k3shell-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 742df7e24d9b0c00d05f3f259bf5facf8202a581b9c8bf306b282eb2190b94a8 |
|
MD5 | 6a65fe29736467273af7c4851d97fff2 |
|
BLAKE2b-256 | e7a0a0652ad53a877431c61050fa3c55de002fc5db91f7cfb66c860ddcc7460c |
File details
Details for the file k3shell-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: k3shell-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c72a8e07a8c7bcefa72bc7b90afdf6709418efc406817bf846d8fbcc1a2c9d06 |
|
MD5 | 190668f27174598ea6c7d4143dfe8c8e |
|
BLAKE2b-256 | 97e541eb5d6d601c300bfa2a948c03a957dc4c3737143df5853c4cdaf17f9f53 |