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.
tl;dr
# 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
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
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.1.2.tar.gz
(2.9 kB
view details)
Built Distribution
File details
Details for the file handofcats-0.1.2.tar.gz
.
File metadata
- Download URL: handofcats-0.1.2.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e604cda5c041dbd0d882c55fb52d68aa87d18fbb23af52beab4e8595b3a29f8 |
|
MD5 | 410c5b7272c85053df9ff270dd3ddefa |
|
BLAKE2b-256 | 6464f9cd4714fc2ad5b8dbcb99a29a95e32f7ca395028a05e111ebc93177f4fa |
File details
Details for the file handofcats-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: handofcats-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c10d6ce81ea128101adcfb66c03eff1c820e05825889b8bb8d9998c395e55b4 |
|
MD5 | 1ce090b41c03769d5af2a718780eb6d1 |
|
BLAKE2b-256 | 7a7d22b0fbac13f4d040435f9dccc9f65e53e46df72d5f869f26c5891e116d3e |