This project demonstrates a minimal (but featureful) command-line interface (CLI) using a plugin-based architecture (PBA). The CLI itself is constructed using Typer.
The PBA is achieved using a combination of:
For a working plugin example, see minimal-pba-cli-plugin-example.
Install the core CLI using the following command:
$ pipx install minimal-pba-cliList available commands using the help:
$ pba-cli --helpList available plugins using the following command (requires a Libraries.io API key):
LIBRARIES_IO_API_KEY=<your API key> pba-cli plugin catalogInstall a plugin using the following command:
$ pba-cli plugin install <plugin name>List installed plugins using the following command:
$ pba-cli plugin listInstall a plugin from a local directory using the following command:
$ pba-cli plugin install-local <path to plugin directory>Uninstall a plugin using the following command:
$ pba-cli plugin uninstall <plugin name>To create a custom script that registers in the CLI, create an executable anywhere on your PATH that follows the naming convention minimal-pba-cli-<name>.
This script will be registered as a command named <name> in the CLI.
As an example, create a script named minimal-pba-cli-hello with the following content:
#!/usr/bin/env sh
echo "Hello, world!"Make the script executable:
$ chmod +x minimal-pba-cli-helloNow, if the script is located in a directory on your PATH, you can run it using the following command:
$ pba-cli hello
Hello, world!Scripts can be written in any language, as long as they are executable and follow the naming convention:
#!/usr/bin/env python
# minimal-pba-cli-quote
import json
import urllib.request
if __name__ == "__main__":
response = urllib.request.urlopen("https://zenquotes.io/api/random")
data = json.loads(response.read().decode("utf-8"))
print(f"""
"{data[0]['q']}"
- {data[0]['a']}
""")$ pba-cli quote
"Educating the mind without educating the heart is no education at all."
- Aristotle