A CLI framework
Project description
CliDev - Python CLI Development Framework
A simple and powerful framework for building interactive command-line applications with dynamic command discovery and hierarchical command organization.
๐ Features
- Hierarchical Command Structure - Organize commands in folders and files
- Dynamic Command Discovery - Automatically discovers commands based on file structure
- Interactive Shell - Rich interactive CLI with tab completion
- Built-in Help System - Use
?to get help on any command or subcommand - Configuration Mode - Special configuration mode with
_configurefolder support - Rich Text Support - Color formatting and styled output
- Customizable Prompts - Set custom prompt text and mode indicators
- Method Chaining - Fluent API for easy CLI setup
๐ฆ Installation
pip install cliframe
๐๏ธ Quick Start
1. Basic Setup
from cliframe import CliService
# Create and run CLI service
cli = CliService()
cli.motd("Welcome to My CLI App!", rich=True)
cli.prompt("myapp")
cli.run()
2. Command Structure
Organize your commands in a cli/ directory structure:
cli/
โโโ show/
โ โโโ __init__.py # 'show' command handler
โ โโโ users.py # 'show users' command
โ โโโ logs/
โ โโโ __init__.py # 'show logs' command
โโโ start.py # 'start' command
โโโ stop.py # 'stop' command
โโโ _configure/ # Configuration commands
โโโ network.py
โโโ system.py
3. Command Handlers
Create command handlers as Python classes:
# cli/start.py
class StartCommand:
"""Start the application service."""
def __init__(self, core):
self.core = core
def run(self, args=None):
"""Start the service with optional arguments."""
print("Service started successfully!")
return "Service is now running"
# Alternative: Use Command or StartCommand class names
class Command: # Will be auto-discovered
def run(self, args=None):
print("Command executed!")
4. Advanced Configuration
from cliframe import CliService
cli = (CliService()
.folder("/path/to/custom/cli/commands") # Custom command folder
.prompt("myapp") # Custom prompt
.prompt_mode_sign("#") # Custom prompt sign
.motd("๐ Welcome to MyApp CLI!", rich=True))
cli.run()
๐ฏ Command Organization
File-based Commands
command.pyโcommandCLI command- Each file should contain a command handler class
Directory-based Commands
command/โcommandCLI command groupcommand/__init__.pyโ Handler for basecommandcommand/subcommand.pyโ Handler forcommand subcommand
Handler Class Discovery
CliDev looks for handler classes in this order:
StartCommandclassCommandclass- Any class ending with
Command - First class found in the module
๐ ๏ธ Interactive Features
Help System
- Type
?at the end of any command to get help command ?- Shows help for the commandcommand sub ?- Shows help for subcommands
Tab Completion
- Smart tab completion for all available commands
- Context-aware completion based on current command path
Configuration Mode
- Create
_configure/folder for configuration commands - Type
configureto enter configuration mode - Prompt changes to
(config)# - Type
exitto leave configuration mode
๐ Example Usage
# Interactive CLI session
myapp> start ? # Get help for start command
myapp> show users # Execute show users command
myapp> configure # Enter configuration mode
myapp(config)# network setup # Run configuration command
myapp(config)# exit # Exit configuration mode
myapp> exit # Exit CLI
๐จ Styling and Output
Color Markers
Use color markers in your command output:
def run(self, args=None):
return "[green]Success![/green] Operation completed [yellow]successfully[/yellow]"
Available Styles
[red]text[/red]- Red text[green]text[/green]- Green text[yellow]text[/yellow]- Yellow text[blue]text[/blue]- Blue text[magenta]text[/magenta]- Magenta text[cyan]text[/cyan]- Cyan text
๐ง API Reference
CliService Class
Methods
__init__(core=None, cli_root=None)- Initialize CLI servicefolder(path)- Set custom CLI commands directoryprompt(text)- Set prompt text (default: "cli")prompt_mode_sign(sign)- Set prompt mode sign (default: ">")motd(message, rich=True)- Set message of the dayrun()- Start the interactive CLI
Method Chaining
All configuration methods return self for easy chaining:
cli = (CliService()
.folder("./my-commands")
.prompt("myapp")
.motd("Welcome!"))
๐ Project Structure
your-project/
โโโ cli/ # Default CLI commands directory
โ โโโ show/
โ โโโ start.py
โ โโโ stop.py
โ โโโ _configure/ # Configuration commands
โโโ main.py # Your CLI application entry point
โโโ requirements.txt
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
This project is licensed under the MIT License.
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 cliframe-0.1.0.tar.gz.
File metadata
- Download URL: cliframe-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c959f4e46b8402e7654f0d2515fbaf085b1bdffb343597902eb601d92cf382a0
|
|
| MD5 |
892155b92112bad60f5b4c6989316618
|
|
| BLAKE2b-256 |
a2724232c2a8bba250ed4fceca1e282121eb9511b19ac453eaa3ef0726995d85
|
File details
Details for the file cliframe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cliframe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a35abcb7879d5824e71c0d4feca461440accc360d9aac51e3fb8bea2c6b9579
|
|
| MD5 |
6d0a1940038a93daf7d13dcc74293ca9
|
|
| BLAKE2b-256 |
c14960706bd5f0dccb1721d2ac2fd54980f21fc022a3d876ecd5868e5c183fb0
|