Add hello world example to readme
This commit is contained in:
parent
4c047bdb2e
commit
7c1a4197be
28
README.md
28
README.md
@ -10,14 +10,32 @@ pip install magicli
|
||||
|
||||
## Get started
|
||||
|
||||
Basic usage example.
|
||||
By default, every function except for the `main` function is callable through command line arguments.
|
||||
Hello world example.
|
||||
|
||||
Docstrings can be added to variables by using `typing.Annotated`.
|
||||
A short option can be added as a third argument to `Annotated`.
|
||||
|
||||
By default the first function is called automatically. All following functions in the file are treated as commands. Functions starting with an underscore are ignored.
|
||||
|
||||
```python
|
||||
from magicli import magicli
|
||||
from typing import Annotated
|
||||
|
||||
def main():
|
||||
magicli()
|
||||
def hello(
|
||||
name: Annotated[str, 'Person to call'],
|
||||
amount: Annotated[int, 'Person to call', 'a']=1,
|
||||
):
|
||||
for _ in range(amount):
|
||||
print(f"Hello {name}!")
|
||||
|
||||
if __name__ == '__main__':
|
||||
import magicli
|
||||
```
|
||||
|
||||
```bash
|
||||
$ hello world 3
|
||||
Hello world!
|
||||
Hello world!
|
||||
Hello world!
|
||||
```
|
||||
|
||||
### Define name of CLI in `setup.py`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user