ggen-config
Configuration parser and validator for ggen.toml files.
Features
- Type-safe parsing: Strongly-typed Rust structs with serde
- Schema validation: Validates configuration against expected schema
- Environment overrides: Support for environment-specific configs (development, staging, production)
- Workspace support: Mono-repo and workspace configuration
- Automatic discovery: Searches upward through directories to find
ggen.toml - Comprehensive error handling: Detailed error types with context
- Well-tested: 24 tests with 100% pass rate
- Documented: Full rustdoc coverage for all public APIs
Installation
Add this to your Cargo.toml:
[]
= { = "4.0.0", = "../ggen-config" }
Usage
Basic Loading
use ;
// Load configuration from file
let config = from_file?;
// Validate the configuration
validate?;
// Access configuration
println!;
if let Some = &config.ai
Auto-Discovery
// Automatically find and load ggen.toml from current or parent directories
let config = find_and_load?;
Environment-Specific Configuration
// Load with environment overrides
let loader = new?;
let dev_config = loader.load_with_env?;
let prod_config = loader.load_with_env?;
Parsing from String
let toml = r#"
[project]
name = "my-project"
version = "1.0.0"
[ai]
provider = "openai"
model = "gpt-4"
"#;
let config = from_str?;
Configuration Schema
Minimal Configuration
[]
= "my-project"
= "1.0.0"
Full Configuration Example
[]
= "advanced-project"
= "2.0.0"
= "A comprehensive example"
= ["Developer <dev@example.com>"]
[]
= "openai"
= "gpt-4"
= 0.7
= 2000
= 30
[]
= "You are an expert developer"
= "Generate code with the following requirements:"
[]
= true
= 0.8
= 3
[]
= "templates"
= "generated"
= true
= true
[]
= "https://example.com/project/"
= { = "https://example.com/project/", = "http://schema.org/" }
[]
= 10
= 1000
= true
[]
= true
= "make.toml"
= ".ggen/cache"
= ".ggen/state.json"
[]
= ["init", "build", "test"]
= ["build", "test", "deploy"]
[]
= true
= true
= true
[]
= true
= 16
= "1GB"
[]
= "info"
= "json"
= "logs/ggen.log"
= "daily"
[]
= true
= true
= true
# Environment-specific overrides
[]
= "gpt-3.5-turbo"
= 0.9
= "debug"
[]
= 0.3
= "warn"
= true
Supported Configuration Sections
Project ([project])
name- Project name (required)version- Semantic version (required)description- Project descriptionauthors- List of authorslicense- License identifierrepository- Repository URL
AI ([ai])
provider- AI provider (openai, ollama, anthropic, etc.)model- Model nametemperature- Generation temperature (0.0-1.0, default: 0.7)max_tokens- Maximum tokens (default: 2000)timeout- Request timeout in seconds (default: 30)
Templates ([templates])
directory- Template source directoryoutput_directory- Output directory for generated filesbackup_enabled- Enable backups before overwritingidempotent- Only update if content changed
RDF ([rdf])
base_uri/base_iri- Base IRI for RDF entitiesprefixes- Namespace prefix mappingsdefault_format- RDF serialization formatcache_queries- Enable query caching
SPARQL ([sparql])
timeout- Query timeout in secondsmax_results- Maximum query resultscache_enabled- Enable query caching
Lifecycle ([lifecycle])
enabled- Enable lifecycle managementconfig_file- Lifecycle config file pathcache_directory- Cache directorystate_file- State file pathphases- Named phase sequences
Security ([security])
path_traversal_protection- Prevent path traversal attacksshell_injection_protection- Prevent shell injectiontemplate_sandboxing- Sandbox template executionrequire_confirmation- Require user confirmationaudit_operations- Audit all operations
Performance ([performance])
parallel_execution- Enable parallel executionmax_workers- Maximum parallel workerscache_size- Cache size limitenable_profiling- Enable performance profiling
Logging ([logging])
level- Log level (trace, debug, info, warn, error)format- Log format (json, text, pretty)file- Log file pathrotation- Log rotation strategy
Validation
The validator checks for:
- Valid semantic versioning
- AI temperature within range (0.0-1.0)
- Valid AI providers
- Valid log levels and formats
- Non-empty required fields
- Valid size formats (e.g., "1GB", "512MB")
use ;
match validate
Error Handling
The crate provides comprehensive error types:
ConfigError::FileNotFound- Configuration file not foundConfigError::Io- I/O error reading fileConfigError::TomlParse- TOML parsing errorConfigError::Validation- Schema validation errorConfigError::InvalidValue- Invalid field valueConfigError::MissingField- Required field missing
Features
Optional Features
graph- Enable graph integration withggen-coreontology- Enable ontology integration withggen-domainfull- Enable all optional features
[]
= { = "4.0.0", = ["full"] }
Testing
The crate includes comprehensive tests:
- 10 unit tests - Core parsing and validation logic
- 9 integration tests - End-to-end scenarios with real configs
- 5 doc tests - Documentation examples
Run tests with:
Examples
See the tests/integration_test.rs file for comprehensive examples including:
- Loading real-world configs from examples
- Environment override handling
- Validation error scenarios
- Default value population
License
MIT
Contributing
This crate is part of the ggen workspace. Contributions are welcome!
Related Crates
ggen-core- Core functionality for graph operationsggen-domain- Domain models and ontology supportggen-cli- Command-line interface using this config parser