Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamic_cli_builder-0.1.16.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamic_cli_builder-0.1.16-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file dynamic_cli_builder-0.1.16.tar.gz.

File metadata

  • Download URL: dynamic_cli_builder-0.1.16.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for dynamic_cli_builder-0.1.16.tar.gz
Algorithm Hash digest
SHA256 71733c87c8efb05e73acf5b69fff709f635d12c287cec04af0f2235cc7bb1335
MD5 94abc34d0bf290ba08ea16c228e387b3
BLAKE2b-256 656854feda375e61064ad50d84d283f5ea30b6622e7af69257ac74d8cc3f5da8

See more details on using hashes here.

File details

Details for the file dynamic_cli_builder-0.1.16-py3-none-any.whl.

File metadata

File hashes

Hashes for dynamic_cli_builder-0.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 b7e4e670679d0e6877dce568024861b3416be1110bdb1c6abd8462955ddee999
MD5 ab0e9ce8a2d137dd69edfba4e4f4f793
BLAKE2b-256 6f450ea8cc7863ea789bb63ee29876b070e460e8dfbb076dffaf5b9174fe8ae3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page