Skip to content

PatrickElmer/magicli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

magiᴄʟɪ✨

Automatically generates a CLI from functions of a module.

Install

pip install magicli

Get started

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:

magicli

You are now able to install your package:

pip install .

And then call it:

$ hello world --times 2
hello world
hello world

Define name of CLI in pyproject.toml

The 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.toml

You can now pip install your code and call it like this:

$ hello world --times 2
hello world
hello world

Using subcommands

# module.py
def hello(): ...

def world(times=1):
    for _ in range(times):
        print("hello world")
$ hello world --times 2
hello world
hello world

Help message

By default, the docstring of the function will be displayed.

If no docstring is specified, an error message will be printed.

Development

Run pytest with coverage report:

python3 -m pytest -s --cov=magicli --cov-report=term-missing

About

Automatically generates a CLI from functions.

Resources

License

Stars

Watchers

Forks

Contributors

Languages