| Crates.io | ggen-config |
| lib.rs | ggen-config |
| version | 5.1.3 |
| created_at | 2025-12-13 19:07:37.704525+00 |
| updated_at | 2026-01-06 22:39:06.267494+00 |
| description | Configuration parser and validator for ggen.toml files |
| homepage | |
| repository | https://github.com/seanchatmangpt/ggen |
| max_upload_size | |
| id | 1983298 |
| size | 196,091 |
Configuration parser and validator for ggen.toml files.
ggen.tomlAdd this to your Cargo.toml:
[dependencies]
ggen-config = { version = "4.0.0", path = "../ggen-config" }
use ggen_config::{ConfigLoader, ConfigValidator};
// Load configuration from file
let config = ConfigLoader::from_file("ggen.toml")?;
// Validate the configuration
ConfigValidator::validate(&config)?;
// Access configuration
println!("Project: {}", config.project.name);
if let Some(ai) = &config.ai {
println!("AI Provider: {}", ai.provider);
}
// Automatically find and load ggen.toml from current or parent directories
let config = ConfigLoader::find_and_load()?;
// Load with environment overrides
let loader = ConfigLoader::new("ggen.toml")?;
let dev_config = loader.load_with_env("development")?;
let prod_config = loader.load_with_env("production")?;
let toml = r#"
[project]
name = "my-project"
version = "1.0.0"
[ai]
provider = "openai"
model = "gpt-4"
"#;
let config = ConfigLoader::from_str(toml)?;
[project]
name = "my-project"
version = "1.0.0"
[project]
name = "advanced-project"
version = "2.0.0"
description = "A comprehensive example"
authors = ["Developer <dev@example.com>"]
[ai]
provider = "openai"
model = "gpt-4"
temperature = 0.7
max_tokens = 2000
timeout = 30
[ai.prompts]
system = "You are an expert developer"
user_prefix = "Generate code with the following requirements:"
[ai.validation]
enabled = true
quality_threshold = 0.8
max_iterations = 3
[templates]
directory = "templates"
output_directory = "generated"
backup_enabled = true
idempotent = true
[rdf]
base_uri = "https://example.com/project/"
prefixes = { ex = "https://example.com/project/", schema = "http://schema.org/" }
[sparql]
timeout = 10
max_results = 1000
cache_enabled = true
[lifecycle]
enabled = true
config_file = "make.toml"
cache_directory = ".ggen/cache"
state_file = ".ggen/state.json"
[lifecycle.phases]
default = ["init", "build", "test"]
production = ["build", "test", "deploy"]
[security]
path_traversal_protection = true
shell_injection_protection = true
template_sandboxing = true
[performance]
parallel_execution = true
max_workers = 16
cache_size = "1GB"
[logging]
level = "info"
format = "json"
file = "logs/ggen.log"
rotation = "daily"
[features]
ai_generation = true
sparql_queries = true
lifecycle_management = true
# Environment-specific overrides
[env.development]
"ai.model" = "gpt-3.5-turbo"
"ai.temperature" = 0.9
"logging.level" = "debug"
[env.production]
"ai.temperature" = 0.3
"logging.level" = "warn"
"security.require_confirmation" = true
[project])name - Project name (required)version - Semantic version (required)description - Project descriptionauthors - List of authorslicense - License identifierrepository - Repository URL[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])directory - Template source directoryoutput_directory - Output directory for generated filesbackup_enabled - Enable backups before overwritingidempotent - Only update if content changed[rdf])base_uri / base_iri - Base IRI for RDF entitiesprefixes - Namespace prefix mappingsdefault_format - RDF serialization formatcache_queries - Enable query caching[sparql])timeout - Query timeout in secondsmax_results - Maximum query resultscache_enabled - Enable query caching[lifecycle])enabled - Enable lifecycle managementconfig_file - Lifecycle config file pathcache_directory - Cache directorystate_file - State file pathphases - Named phase sequences[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])parallel_execution - Enable parallel executionmax_workers - Maximum parallel workerscache_size - Cache size limitenable_profiling - Enable performance profiling[logging])level - Log level (trace, debug, info, warn, error)format - Log format (json, text, pretty)file - Log file pathrotation - Log rotation strategyThe validator checks for:
use ggen_config::{ConfigValidator, ConfigError};
match ConfigValidator::validate(&config) {
Ok(_) => println!("Configuration is valid"),
Err(ConfigError::Validation(msg)) => {
eprintln!("Validation errors: {}", msg);
}
Err(e) => eprintln!("Error: {}", e),
}
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 missinggraph - Enable graph integration with ggen-coreontology - Enable ontology integration with ggen-domainfull - Enable all optional features[dependencies]
ggen-config = { version = "4.0.0", features = ["full"] }
The crate includes comprehensive tests:
Run tests with:
cargo test -p ggen-config
See the tests/integration_test.rs file for comprehensive examples including:
MIT
This crate is part of the ggen workspace. Contributions are welcome!
ggen-core - Core functionality for graph operationsggen-domain - Domain models and ontology supportggen-cli - Command-line interface using this config parser