A Python library for dynamically building CLI tools from YAML configurations.
Project description
Dynamic CLI Builder
Dynamic CLI Builder is a tool to help you create command-line interfaces (CLI) dynamically with ease.
Features
- Easy to use
- Highly customizable
- Supports multiple command structures
Installation
To install Dynamic CLI Builder, use the following command:
pip install dynamic-cli-builder
Usage
Here is a simple example to get you started:
Create Actions
Actions are basically function to be executed base on command.
For instance actions.py
def say_hello(name: str, age: int):
print(f"Hello {name}!, you are {age} years old.")
# Action Registry
ACTIONS = {
"say_hello": say_hello,
}
you can have multiple function registered
Create yaml config
config.yaml
description: "Dynamic CLI Builder Example"
commands:
- name: say_hello
description: "Say Hello..."
args:
- name: name
type: str
help: "Name of the user."
action: say_hello
Add rules for custom validation
- min, max validation
description: "Dynamic CLI Builder Example"
commands:
- name: say_hello
description: "Say Hello..."
args:
- name: name
type: str
help: "Name of the user."
- name: age
type: int
help: "Age of the user."
rules:
min: 1
max: 99
action: say_hello
- for more control, you could also use regex
description: "Dynamic CLI Builder Example"
commands:
- name: say_hello
description: "Say Hello..."
args:
- name: name
type: str
help: "Name of the user."
- name: age
type: int
help: "Age of the user."
rules:
regex: "^[1-9][0-9]$"
action: say_hello
Main file main.py
To bind this all together
from dynamic_cli_builder import run_builder
from actions import ACTIONS
run_builder('config.yaml', ACTIONS)
CLI Command
Global Help
python3 <name_of_main_file> -h
For Instance:
python3 main.py -h
command specific help
python3 <name_of_main_file> <name_of_command> -h
For Instance:
python3 main.py say_hello --name world --age 4530000000
You should see
Hello World!, you are 4530000000 years old
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dynamic_cli_builder-0.1.14.tar.gz.
File metadata
- Download URL: dynamic_cli_builder-0.1.14.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e015a1d95c266cd7085d6071432f0d5fdbd1d27b8e39265c01556427ef4915d
|
|
| MD5 |
785d6f97dc7e2f52ae02fce3c08cb6bd
|
|
| BLAKE2b-256 |
f3bbbdb7f303552b97520a81548c01d4345bc88f348673e30e1922248b5cee79
|
File details
Details for the file dynamic_cli_builder-0.1.14-py3-none-any.whl.
File metadata
- Download URL: dynamic_cli_builder-0.1.14-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d655b21a0d9a1db39f6bcb6926f245e49a2c80ece94b96daefc39dbac81458f7
|
|
| MD5 |
34341b4f2bc7334aaec55beb663b647c
|
|
| BLAKE2b-256 |
51de6432e1d263aaf05a9801cce1ceef52713f8f8e52ce78179557fb0484abeb
|