Werkzeug-style command parsing.
Project description
# commandlet
Werkzeug-style commands.
## Usage
```
from commandlet.parser import Parser
p = Parser()
@p.command('test', 'test <int:times> <str:string>')
def do_test(times, string):
"""Test a certain number of times."""
for n in range(times):
print('[%d]: %s' % (n, string))
p.handle_command('test 4 Hello world.')
```
As you can see, you can decorate functions with the Parser.command decorator to make them callable. They should all be given a name (used for pretty-printing mainly), and an argument string, which looks very similar to those seen in command line programs... And [Werkzeug](https://palletsprojects.com/p/werkzeug/).
You can also add extra filters:
```
@p.filter('reverse')
def do_reverse(text):
return (text, ''.join(reversed(text)))
@p.command('reverse', 'reverse <reverse:string>')
def reverse_command(string):
original, new = string
print('Reversing %r gives %r.' % (original, new))
```
You can see the full list of filters by examining the Parser.filters dictionary. By default, str, int, and float are supported.
Werkzeug-style commands.
## Usage
```
from commandlet.parser import Parser
p = Parser()
@p.command('test', 'test <int:times> <str:string>')
def do_test(times, string):
"""Test a certain number of times."""
for n in range(times):
print('[%d]: %s' % (n, string))
p.handle_command('test 4 Hello world.')
```
As you can see, you can decorate functions with the Parser.command decorator to make them callable. They should all be given a name (used for pretty-printing mainly), and an argument string, which looks very similar to those seen in command line programs... And [Werkzeug](https://palletsprojects.com/p/werkzeug/).
You can also add extra filters:
```
@p.filter('reverse')
def do_reverse(text):
return (text, ''.join(reversed(text)))
@p.command('reverse', 'reverse <reverse:string>')
def reverse_command(string):
original, new = string
print('Reversing %r gives %r.' % (original, new))
```
You can see the full list of filters by examining the Parser.filters dictionary. By default, str, int, and float are supported.
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
commandlet-0.4.1.tar.gz
(11.1 kB
view details)
Built Distribution
File details
Details for the file commandlet-0.4.1.tar.gz
.
File metadata
- Download URL: commandlet-0.4.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b6dd45f898e21018d7a07b1d84ba3cf68b323c1889f04e294a1b50bcfea8200 |
|
MD5 | e49289aee49ca2fb4d09f94875590ff9 |
|
BLAKE2b-256 | 6c9b7963dcdd669f618136a21ccf6f370747e812d4b462c017fa85d7138f5d84 |
Provenance
File details
Details for the file commandlet-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: commandlet-0.4.1-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45d448c6d0b068769ec2c036ab63d75698982a49c673594a3bd3aba8af375b93 |
|
MD5 | cd354a6d3de5430b656c38036e3ca5dd |
|
BLAKE2b-256 | a89e6d8d2512da409990dc00bc66a8902eac0a67af82729122079b74f4382b38 |