Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Unilang
Define your command-line utility interface once and get consistent interaction across multiple modalities — CLI, GUI, TUI, AUI, Web APIs, and more—essentially for free.
Overview
Unilang is a command framework that allows you to define commands declaratively and execute them across different modalities. It provides a complete pipeline from command definition to execution, including parsing, semantic analysis, validation, and help generation.
Core Features
- 📝 Declarative Command Definition: Define commands using structured data with comprehensive metadata
- 🏪 Centralized Registry: Manage all commands in a single registry with namespace organization
- 📄 External Configuration: Load command definitions from YAML and JSON files
- 🔍 Robust Parsing: Convert text input to structured instructions using the unilang_parser
- 🧠 Semantic Analysis: Validate commands against registry with type checking and constraint enforcement
- ⚡ Flexible Execution: Execute commands with proper context and error handling
- 🚀 High-Level Pipeline API: Simplified workflow helpers for common usage patterns
- 📚 Automatic Help: Generate comprehensive help documentation from command definitions
- 🛡️ Error Management: Structured error handling with meaningful error codes and messages
- 📦 Batch Processing: Execute multiple commands with comprehensive result tracking
- 🔐 Command Validation: Validate commands without execution for safety checks
Data Types & Validation
Supported Argument Types
- Basic Types: String, Integer, Float, Boolean, Path, File, Directory, URL, DateTime, Pattern
- Choice Types: Enum with predefined options
- Collection Types: List and Map with custom delimiters
- Complex Types: JSON strings and objects
Validation Rules
- Numeric: min/max value constraints
- String: length constraints and regex pattern matching
- Collection: minimum item count requirements
Argument Attributes
- Optional: Arguments that are not required
- Multiple: Arguments that can accept multiple values
- Default: Arguments with default values
- Sensitive: Arguments containing sensitive data
- Interactive: Arguments that may require user interaction
Step-by-Step Tutorial
The examples/ directory contains comprehensive tutorials demonstrating all capabilities:
01. Basic Command Registration
File: examples/01_basic_command_registration.rs
Learn the fundamentals of command registration:
- Creating a command registry
- Defining commands with metadata
- Implementing command routines
- Registering commands with their execution logic
02. Argument Types
File: examples/02_argument_types.rs
Explore all supported argument types:
- String, Integer, Float, Boolean types
- Path, File, Directory, URL types
- DateTime, Pattern, Enum types
- Type validation and conversion
03. Collection Types
File: examples/03_collection_types.rs
Master collection types and custom delimiters:
- List types with various delimiters
- Map types with key-value pairs
- Custom delimiter configuration
- Nested collection structures
04. Validation Rules
File: examples/04_validation_rules.rs
Implement robust input validation:
- Numeric constraints (min/max)
- String length validation
- Pattern matching with regex
- Argument attribute configuration
05. Namespaces and Aliases
File: examples/05_namespaces_and_aliases.rs
Organize commands with namespaces and aliases:
- Namespace-based command organization
- Command and argument aliases
- Hierarchical command structure
- Alias resolution system
06. Help System
File: examples/06_help_system.rs
Generate comprehensive command documentation:
- Automatic help generation
- Command listing and detailed help
- Documentation best practices
- Interactive help access
07. YAML and JSON Loading
File: examples/07_yaml_json_loading.rs
Load commands from external configuration files:
- YAML command definitions
- JSON command specifications
- External file loading
- Configuration management
08. Semantic Analysis
File: examples/08_semantic_analysis.rs
Understand command validation and verification:
- Parsing to semantic analysis pipeline
- Command existence validation
- Argument binding and type checking
- Error detection and reporting
09. Command Execution
File: examples/09_command_execution.rs
Execute verified commands with proper context:
- Command routine implementation
- Execution context usage
- Error handling patterns
- Batch command processing
10. Full Pipeline
File: examples/10_full_pipeline.rs
See the complete Unilang pipeline in action:
- End-to-end command processing
- Registry setup and management
- Interactive command processing
- Real-world usage patterns
11. High-Level Pipeline API
File: examples/11_pipeline_api.rs
Master the high-level Pipeline API for simplified workflows:
- Single command processing with error handling
- Batch processing with success tracking
- Sequence processing with fail-fast behavior
- Command validation without execution
- Performance optimization through component reuse
Quick Start Examples
Basic Command Registration
use CommandRegistry;
use ;
use Value;
// Create registry
let mut registry = new;
// Define command
let greet_cmd = former
.name
.namespace
.description
.hint
.status
.version
.aliases
.tags
.permissions
.idempotent
.deprecation_message
.http_method_hint
.examples
.arguments
.end;
// Define routine
let routine = Boxnew;
// Register command
registry.command_add_runtime?;
High-Level Pipeline API
use Pipeline;
use ExecutionContext;
// Create pipeline with registry
let pipeline = new;
// Process single command
let result = pipeline.process_command_simple;
if result.success
// Process batch of commands
let commands = vec!;
let batch_result = pipeline.process_batch;
println!;
// Validate command without execution
match pipeline.validate_command
External Configuration Loading
use CommandRegistry;
let yaml_config = r#"
- name: "hello"
namespace: ""
description: "Hello world command"
arguments:
- name: "target"
kind: "String"
hint: "Who to greet"
"#;
let registry = builder
.load_from_yaml_str?
.build;
CLI Usage
The included CLI demonstrates practical usage:
# Build the CLI
# Show available commands
# Execute commands
# Get command help
Architecture
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Command │ │ External Config │ │ Help │
│ Registration │────│ (YAML/JSON) │────│ Generation │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────────┐
│ Command Registry │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Text Input │────│ Parser │────│ Instructions │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Semantic │────│ Verified │────│ Interpreter │
│ Analysis │ │ Commands │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Error │ │ Execution │────│ Output Data │
│ Reports │ │ Context │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
Key Components
Data Structures
- CommandDefinition: Complete command specification with metadata
- ArgumentDefinition: Argument specification with validation rules
- Kind: Type system for arguments with validation support
- VerifiedCommand: Validated command ready for execution
- OutputData: Structured command execution results
- ErrorData: Structured error information with codes and messages
Core Systems
- CommandRegistry: Central command storage and management
- SemanticAnalyzer: Command validation and verification
- Interpreter: Command execution engine
- HelpGenerator: Automatic documentation generation
- Pipeline: High-level workflow orchestration
Pipeline API
- Pipeline: Main high-level interface for command processing
- CommandResult: Single command execution result with success/error info
- BatchResult: Batch processing results with statistics
- Convenience Functions: One-off processing helpers
Processing Modes
- Single Command: Process one command with full error handling
- Batch Processing: Process multiple commands independently
- Sequence Processing: Process commands with fail-fast behavior
- Validation Only: Validate commands without execution
Error Handling
- Structured Errors: Machine-readable error codes with human descriptions
- Validation Errors: Constraint violation reporting
- Execution Errors: Runtime error handling
- Pipeline Errors: High-level workflow error management
API Reference
Pipeline API
The Pipeline API provides high-level interfaces for common Unilang workflows:
Pipeline Structure
Result Types
Convenience Functions
// Process single command without creating Pipeline
;
// Validate single command without creating Pipeline
;
Usage Patterns
Basic Command Processing
use Pipeline;
let pipeline = new;
let result = pipeline.process_command_simple;
if result.success else
Batch Processing with Error Handling
let commands = vec!;
let batch_result = pipeline.process_batch;
println!;
for result in &batch_result.results
Command Validation
// Validate before execution
match pipeline.validate_command
Performance-Optimized Processing
// Reuse pipeline for multiple commands (faster)
let pipeline = new;
for cmd in commands
// vs. one-off processing (slower due to repeated setup)
for cmd in commands
Testing
Run the test suite to verify functionality:
# Run all tests
# Run specific test categories
# Run integration tests
# Run pipeline API tests
# Run examples as tests
Contributing
- Study the examples to understand the architecture
- Check existing tests for patterns
- Add tests for new functionality
- Follow the established code style
- Update documentation as needed
License
MIT License - see LICENSE file for details.