python function to command translator
Project description
A tiny Converter that making executable command script from python function. If the function has sphinx autodoc style docstring, it is also used.
this module has two functions.
as_command()
describe()
If you just convert python function to executable command, then use as_command(). And, you want to show a list of managemented commands, describe() is helpful.
as_command()
# greeting.py
from handofcats import as_command
@as_command
def greeting(message, is_surprised=False, name="foo"):
suffix = "!" if is_surprised else ""
print("{name}: {message}{suffix}".format(name=name, message=message, suffix=suffix))
$ python greeting.py
usage: greeting.py [-h] [--is-surprised] [--name NAME] message
greeting.py: error: too few arguments
$ python greeting.py -h
usage: greeting.py [-h] [--is-surprised] [--name NAME] message
positional arguments:
message
optional arguments:
-h, --help show this help message and exit
--is-surprised
--name NAME
$ python greeting.py hello
foo: hello
$ python greeting.py --is-surprised hello
foo: hello!
$ python greeting.py --is-surprised --name=bar bye
bar: bye!
with docstring (additional feature)
from handofcats import as_command
@as_command
def greeting(message, is_surprised=False, name="foo"):
""" greeting message
:param message: message of greeting
:param is_surprised: surprised or not (default=False)
:param name: name of actor
"""
suffix = "!" if is_surprised else ""
print("{name}: {message}{suffix}".format(name=name, message=message, suffix=suffix))
$ python greeting.py -h
usage: greeting.py [-h] [--is-surprised] [--name NAME] message
greeting message
positional arguments:
message message of greeting
optional arguments:
-h, --help show this help message and exit
--is-surprised surprised or not (default=False)
--name NAME name of actor
describe()
$ tree foo/
foo/
├── __init__.py
├── __main__.py
├── bye.py
└── hello.py
$ cat foo/__main__.py
from handofcats import describe
describe()
$ python -m foo
avaiable commands are here. (with --full option, showing full text)
- foo.bye
- foo.hello -- hello message
$ cat foo/hello.py
from handofcats import as_command
@as_command
def hello():
"""
hello message
"""
print("hello")
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
handofcats-0.3.0.tar.gz
(6.2 kB
view details)
Built Distribution
File details
Details for the file handofcats-0.3.0.tar.gz
.
File metadata
- Download URL: handofcats-0.3.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaac1c0471ec8d2a2df027d3ce0fdb1b8110eed31a158f4918f441180a38fbd8 |
|
MD5 | 8fb79a3cd9af9891ee123f1f2c8b7d61 |
|
BLAKE2b-256 | b7f38973920bc771c81300a137f406dea3a76c153f29fd9df3279d1ce07c0d33 |
File details
Details for the file handofcats-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: handofcats-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3616f16dea784fe0867b9d4b93e1d3dafbbb0c70b6fd6f1154c43393a89dd89 |
|
MD5 | 4ba22b5a4f4d64e158bebab84c098610 |
|
BLAKE2b-256 | 698405ffe1babcdc2a0a4baa0dfef7b1259f2cd8f71d5b7e8bf361c506131dde |