raz-config
Configuration management for RAZ - handles loading, saving, validation, and inheritance.
Features
- Hierarchical configuration (Global → Workspace → File)
- Configuration versioning and migration
- Built-in validation
- TOML-based configuration files
- Type-safe configuration schema
- Support for command overrides
- Template system for common setups
Usage
use ;
Template System
RAZ provides a template system for initializing projects with common configurations and extending support for new frameworks.
Current Status
⚠️ Note: Custom template files (.raz/templates/) are not yet implemented in the CLI. This guide documents the planned architecture and how to work with the current system.
Current Options
Built-in Templates
The configuration system includes built-in templates for common project types:
web- Web development with Leptos and Dioxusgame- Game development with Bevylibrary- Library development focusdesktop- Desktop applications with Tauri and Egui
Project-Specific Configuration
You can configure RAZ behavior using .raz/config.toml:
Creating Custom Templates
Template Structure
Custom templates are defined in .raz/templates/ directory in your workspace:
.raz/
├── templates/
│ ├── my-framework.toml
│ ├── custom-test.toml
│ └── microservice.toml
└── overrides.toml
Basic Template Format
# .raz/templates/my-framework.toml
[]
= "my-framework"
= "Custom framework template"
= "1.0.0"
[]
# Files that indicate this framework
= [
"my-framework.toml",
"Cargo.toml:dependencies.my-framework",
"src/main.rs:use my_framework::"
]
# Command patterns for different file types
[]
= "cargo"
= ["run", "--bin", "{binary_name}"]
= { = "development" }
[]
= "cargo"
= ["test", "--package", "{package_name}", "--", "{test_name}", "--exact"]
= "{workspace_root}"
[]
= "my-framework"
= ["run", "example", "{example_name}"]
[]
= "my-framework"
= ["serve", "--port", "3000"]
= true
# Framework-specific options
[]
= [
"--port",
"--env",
"--config",
"--verbose"
]
[]
= [
"MY_FRAMEWORK_ENV",
"MY_FRAMEWORK_CONFIG",
"PORT"
]
Advanced Template Features
Conditional Commands
# Different commands based on file content or location
[]
= "cargo"
= ["test"]
[]
# Use different args for integration tests
= ["test", "--test", "{test_name}"]
# Use different args for unit tests
= ["test", "--package", "{package_name}", "--", "{test_name}", "--exact"]
[]
# Custom handling for specific file patterns
= { = ["test", "--test", "{file_stem}"] }
= { = "cargo", = ["bench", "--bench", "{file_stem}"] }
Dynamic Variables
[]
# Define custom variables for use in commands
= "3000"
= "{workspace_root}/config.toml"
= "{package_name}-server"
[]
= "my-framework"
= ["serve", "--port", "{port}", "--config", "{config_file}"]
Environment Detection
[]
# Different configurations for different environments
[]
= { = "dev", = "debug" }
= ["--reload"]
[]
= { = "prod" }
= ["--optimize"]
[]
= { = "test", = "1" }
= ["--no-capture"]
Custom Framework Providers
For more complex frameworks, create a custom provider:
Provider Structure
// src/providers/my_framework.rs
use ;
use Path;
;
Registering Custom Providers
// In your application or RAZ configuration
use ProviderRegistry;
use MyFrameworkProvider;
let mut registry = new;
registry.register;
// Use the registry for command generation
let commands = registry.generate_commands?;
Project-Specific Configuration
Workspace Templates
Create workspace-specific templates in .raz/config.toml:
# .raz/config.toml
[]
= "my-project"
= "microservice"
[]
= "rust-binary" # Inherit from built-in template
[]
# Override test command for this project
= "cargo"
= ["test", "--features", "integration-tests"]
= { = "sqlite::memory:" }
[]
= "cargo"
= ["run", "--bin", "server"]
= { = "8080", = "info" }
# Custom commands specific to this project
[]
= "cargo"
= ["run", "--bin", "migrate"]
= "Run database migrations"
[]
= "docker"
= ["build", "-t", "my-project", "."]
= "Build Docker image"
File-Specific Overrides
# .raz/config.toml
[]
# Special handling for specific files
= { = "binary-with-args" }
= { = "integration-test" }
= { = "example-with-features" }
[]
[]
= "cargo"
= ["run", "--bin", "{file_stem}", "--"]
= true # Ask user for arguments
[]
[]
= "cargo"
= ["test", "--test", "{file_stem}", "--features", "integration"]
= { = "test.db" }
Examples
Web Framework Template
# .raz/templates/axum-web.toml
[]
= "axum-web"
= "Axum web framework template"
[]
= [
"Cargo.toml:dependencies.axum",
"src/main.rs:use axum::"
]
[]
= "cargo"
= ["run"]
= { = "info,my_app=debug" }
= true
= "Start Axum server"
[]
= "cargo"
= ["test", "--", "{test_name}", "--exact"]
[]
= "cargo"
= ["watch", "-x", "run"]
= true
= "Watch and restart server"
[]
= ["--port", "--host", "--env", "--features"]
[]
= ["PORT", "HOST", "DATABASE_URL", "RUST_LOG"]
Game Development Template
# .raz/templates/bevy-game.toml
[]
= "bevy-game"
= "Bevy game engine template"
[]
= [
"Cargo.toml:dependencies.bevy",
"src/main.rs:use bevy::"
]
[]
= "cargo"
= ["run", "--features", "bevy/dynamic_linking"]
= { = "info" }
= "Run game (fast compile)"
[]
= "cargo"
= ["run", "--release"]
= "Run game (optimized)"
[]
= "cargo"
= ["build", "--target", "wasm32-unknown-unknown", "--release"]
= "Build for web"
[]
= "basic-http-server"
= ["--addr", "127.0.0.1:4000", "target/wasm32-unknown-unknown/release/"]
= true
= "Serve web build"
CLI Tool Template
# .raz/templates/cli-tool.toml
[]
= "cli-tool"
= "Command-line tool template"
[]
= [
"Cargo.toml:dependencies.clap",
"src/main.rs:use clap::"
]
[]
= "cargo"
= ["run", "--"]
= true
= "Run CLI tool"
[]
= "cargo"
= ["install", "--path", "."]
= "Install locally"
[]
= "cargo"
= ["test", "--", "--test-threads", "1"]
= "Run CLI tests"
[]
= ["--verbose", "--quiet", "--help", "--version"]
Best Practices
Template Design
- Keep it simple: Start with basic commands and add complexity gradually
- Use descriptive labels: Make command purposes clear
- Provide sensible defaults: Reduce configuration burden
- Document variables: Comment template variables and their purposes
Framework Detection
- Use multiple indicators: Don't rely on a single file for detection
- Check dependencies: Parse Cargo.toml for framework dependencies
- Validate context: Ensure detected framework is actually being used
- Handle versions: Account for different framework versions
Command Generation
- Prioritize commands: Put most common commands first
- Handle edge cases: Account for different project structures
- Provide fallbacks: Have backup commands when primary ones fail
- Support customization: Allow users to override default behavior
Template Usage
Templates can be accessed programmatically through the ConfigTemplates API:
use ConfigTemplates;
// Get a built-in template
let web_config = web_development;
let game_config = game_development;
// List available templates
let templates = list_templates;
This system allows RAZ to support any framework or development pattern while maintaining its core philosophy of intelligent, context-aware command generation.