a module for parsing and processing commands.
Project description
cmdtools
a module for parsing and processing commands.
Installation
to install this module you can use the methods below
-
using pip:
- from pypi:
pip install cmdtools-py
- from github repository:
pip install git+https://github.com/HugeBrain16/cmdtools.git
- from pypi:
-
from source:
python setup.py install
Examples
Basic example
import cmdtools
def ping(raw_args, args):
print("pong.")
_cmd = cmdtools.Cmd('/ping')
_cmd.parse()
cmdtools.ProcessCmd(_cmd, ping)
Parse command with arguments
import cmdtools
def greet(raw_args, args):
print(f"Hello, {greet.name}, nice to meet you")
_cmd = cmdtools.Cmd('/greet "Josh"')
_cmd.parse()
cmdtools.ProcessCmd(_cmd, greet,
attr= { # assign attributes to the callback
'name': _cmd.args[0]
}
)
Parsing command with more than one argument and different data types
import cmdtools
def give(raw_args, args):
print(f"You gave {give.item_amount} {give.item_name}s to {give.name}")
_cmd = cmdtools.Cmd('/give "Josh" "Apple" 10')
_cmd.parse(eval=True) # we're going to use `MatchArgs` function which only supported for `eval` parsed command arguments
# check command
if cmdtools.MatchArgs(_cmd, 'ssi', max_args=3): # format indicates ['str','str','int'], only match 3 arguments
cmdtools.ProcessCmd(_cmd, give,
attr={
'name': _cmd.args[0],
'item_name': _cmd.args[1],
'item_amount': _cmd.args[2]
}
)
else:
print('Correct Usage: /give <name: [str]> <item-name: [str]> <item-amount: [int]>')
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-1.0.0.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for cmdtools_py-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8df000146cfe6501a88281bd833985a4d1254c02295ac2bf8cee102ca04a214d |
|
MD5 | c51eac535c2c2eea2a50ec26ad41ca0a |
|
BLAKE2b-256 | bd6ae7803e3a73cee5101fd0c1aaa5a3ff02cf5bb01b18bba332545c039f310b |