Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paolosarti/sig2cli
Turn function signatures into Command Line Interfaces
https://github.com/paolosarti/sig2cli
Last synced: about 1 month ago
JSON representation
Turn function signatures into Command Line Interfaces
- Host: GitHub
- URL: https://github.com/paolosarti/sig2cli
- Owner: PaoloSarti
- License: mit
- Created: 2017-12-02T11:21:53.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-27T15:01:26.000Z (almost 7 years ago)
- Last Synced: 2024-11-03T12:35:04.779Z (about 2 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sig2cli
*Turn function signatures into Command Line Interfaces*Just define a function signature as the entry point of your program instead of writing a lot of verbose argparse code.
## Example
```python
import sig2clidef hi(name, times=1, enthusiast=False):
"""Say hi!
Arguments
name: person to greet
times: how many times to greet
enthusiast: add an exclamation mark
"""
for _ in range(times):
print('Hi {}{}'.format(name, '!' if enthusiast else ''))if __name__ == "__main__":
sig2cli.run(hi)
```
The command line interface is automatically created from the signature and the docstring.
```
$ python my_script.py -h
usage: sig2cli.py [-h] -n NAME [-t TIMES] [-e]Say hi!
optional arguments:
-h, --help show this help message and exit
-n NAME, --name NAME person to greet
-t TIMES, --times TIMES
how many times to greet (default: 1)
-e, --enthusiast add an exclamation mark at the end (default: False)$ python my_script.py --name John -t 2 -e
Hi John!
Hi John!
```## Installation
Install it with pip:
```
pip install sig2cli
```## Description
The command line description is taken from the docstring of the method, with the following conventions:
* the description is everything that precedes the string "Arg" (so Arguments, Args) that starts the argument list.
* each argument should be in the format : [argtype]Types are inferred from default arguments, or taken from the docstring if specified.
Allowed types are "str", "int", "float", "bool".
It supports short args (the first letter of each argument) only if they are all different and no argument starts with "h" (reserved for help)
Default bool arguments are registered as flags.