command text parser and command processor
Project description
Installation
pip install --upgrade cmdtools-py
install latest commit from GitHub
pip install git+https://github.com/HugeBrain16/cmdtools.git
Examples
more examples here
Basic example
import cmdtools
def ping():
print("pong.")
cmd = cmdtools.Cmd('/ping')
cmd.process_cmd(ping)
Command with arguments
import cmdtools
def give(name, item_name, item_amount):
print(f"You gave {item_amount} {item_name}s to {name}")
# surround argument that contains whitespaces with quotes
# set `convert_args` to `True` to automatically convert numbers argument
# this will raise an exception,
# if the number of arguments provided is less than the number of positional callback parameters.
cmd = cmdtools.Cmd('/give Josh "Golden Apple" 10', convert_args=True)
# check for command instance arguments data type.
# format indicates ['str','str','int'].
# integer or float can also match string format, and character 'c' if the argument only has 1 digit.
# `max_args` set to 3, check the first 3 arguments, the rest will get ignored,
# otherwise if it set to default,
# it will raise an exception if the number of arguments is not equal to the number of formats
if cmd.match_args('ssi', max_args=3):
cmd.process_cmd(give)
else:
print('Correct Usage: /give <name: [str]> <item-name: [str]> <item-amount: [int]>')
Links
PyPI project: https://pypi.org/project/cmdtools-py
Source code: https://github.com/HugeBrain16/cmdtools
Issues tracker: https://github.com/HugeBrain16/cmdtools/issues
Documentation: ...
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
cmdtools-py-2.4.8.tar.gz
(9.2 kB
view hashes)
Built Distribution
Close
Hashes for cmdtools_py-2.4.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce6eb9377ee483bf298bb92abdb3bf05057fa34587de9ffbdd4613592b021e7d |
|
MD5 | bb8bef4ced240c39e77dd3b421a4b08e |
|
BLAKE2b-256 | a7be89c1a2facccc026774b9719545d13518fb6c4a241626aa9ddc0b307e2eea |