Changes to readme
This commit is contained in:
parent
325551343b
commit
b2da98add7
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
# Getting started
|
# Get started
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|||||||
76
readme.md
76
readme.md
@ -4,13 +4,85 @@ Automatically call args parsed by `docopt` as functions.
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
`pip install git+https://git.beelm.eu/patrick/magicli`
|
```
|
||||||
|
pip install git+https://git.beelm.eu/patrick/magicli
|
||||||
|
```
|
||||||
|
|
||||||
## Getting started
|
## Get started
|
||||||
|
|
||||||
|
Basic usage example.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
from magicli import magicli
|
from magicli import magicli
|
||||||
|
|
||||||
|
def cli():
|
||||||
|
magicli(docopt(__doc__))
|
||||||
|
```
|
||||||
|
|
||||||
|
Functions that share a name with the keys or `dict` returned by `docopt` are automatically called with all required args if specified (Note that keys are converted to valid python function names, i.e. stripping the characters `<` `>` `-` and replacing `-` with `_`) .
|
||||||
|
|
||||||
|
All functions that are called this way need to be imported.
|
||||||
|
|
||||||
|
`magicli` also returns a dict with converted keys, and these can be used as `args` if needed.
|
||||||
|
|
||||||
|
```python
|
||||||
args = magicli(docopt(__doc__))
|
args = magicli(docopt(__doc__))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Minimal `Hello World` example
|
||||||
|
|
||||||
|
### hello.py
|
||||||
|
|
||||||
|
```python
|
||||||
|
"""
|
||||||
|
Usage:
|
||||||
|
hello say <name> [--amount <amount>]
|
||||||
|
|
||||||
|
-a, --amount How often do greet
|
||||||
|
"""
|
||||||
|
|
||||||
|
from docopt import docopt
|
||||||
|
from magicli import magicli
|
||||||
|
|
||||||
|
|
||||||
|
def cli():
|
||||||
|
magicli(docopt(__doc__))
|
||||||
|
|
||||||
|
|
||||||
|
def say(name, amount = 1):
|
||||||
|
for _ in range(int(amount)):
|
||||||
|
print(f'Hello {name}!')
|
||||||
|
```
|
||||||
|
|
||||||
|
### setup.py
|
||||||
|
```python
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='hello',
|
||||||
|
version='0.1.0',
|
||||||
|
install_requires=[
|
||||||
|
'docopt'
|
||||||
|
],
|
||||||
|
entry_points={
|
||||||
|
'console_scripts':[
|
||||||
|
'hello=hello:cli'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Calling the script:
|
||||||
|
|
||||||
|
```
|
||||||
|
hello say World 3
|
||||||
|
```
|
||||||
|
results in the following output
|
||||||
|
|
||||||
|
```
|
||||||
|
Hello World!
|
||||||
|
Hello World!
|
||||||
|
Hello World!
|
||||||
|
```
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user