Skip to main content

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.

Project details


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.1.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

commandlet-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file commandlet-0.1.0.tar.gz.

File metadata

  • Download URL: commandlet-0.1.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for commandlet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c575453d6fb70db691b964912b22e50d54aa1eeb73cbcb8c056e2945be7870e3
MD5 167945139286793b60f3af94af288b4e
BLAKE2b-256 c661e625e9100caeb8a9fc7abe0399bee88389430faafd873ff5521c89046d64

See more details on using hashes here.

Provenance

File details

Details for the file commandlet-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: commandlet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 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

Hashes for commandlet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cfaa9058476aae806f243aaca672a37800e69fea01f2976798c642c7d4962b9
MD5 ea1322b7a91fc5b2a4a483cb85a21db3
BLAKE2b-256 9aa0f1c9f2ffa52b6426a46d8d6122262a1605654381041412cc71a200274b97

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page