Automatically generates a CLI from functions of a module.
pip install magicli
Simple usage example.
# module.py
def hello(name, times=1):
for _ in range(times):
print("hello", name)Then run this in your terminal to initialize the CLI:
magicliYou are now able to install your package:
pip install .And then call it:
$ hello world --times 2
hello world
hello worldThe terminal command magicli adds the following to your pyproject.toml.
[project.scripts]
hello = "magicli:magicli"Important: Make sure the name of your CLI, the module name and the name of the function to be called are the same!
.
├── hello.py
└── pyproject.tomlYou can now pip install your code and call it like this:
$ hello world --times 2
hello world
hello world# module.py
def hello(): ...
def world(times=1):
for _ in range(times):
print("hello world")$ hello world --times 2
hello world
hello worldBy default, the docstring of the function will be displayed.
If no docstring is specified, an error message will be printed.
Run pytest with coverage report:
python3 -m pytest -s --cov=magicli --cov-report=term-missing