From 7c1a4197bef023e74eb75cdb3bfbd5db411532b9 Mon Sep 17 00:00:00 2001 From: Patrick Elmer Date: Mon, 18 Sep 2023 10:55:00 +0900 Subject: [PATCH] Add hello world example to readme --- README.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ed49f1d..a6d64ca 100644 --- a/README.md +++ b/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`