45 lines
1.7 KiB
Rust
45 lines
1.7 KiB
Rust
|
|
//! Example of using configuration discovery functionality.
|
||
|
|
//!
|
||
|
|
//! This example demonstrates how to find configuration files
|
||
|
|
//! using the proper precedence hierarchy:
|
||
|
|
//! 1. Explicit config path
|
||
|
|
//! 2. Global vapora config (~/.vapora/)
|
||
|
|
//! 3. Global syntaxis config (~/.syntaxis/)
|
||
|
|
//! 4. Local vapora config (./.vapora/)
|
||
|
|
//! 5. Local syntaxis config (./.syntaxis/)
|
||
|
|
|
||
|
|
use tools_shared::find_config_path;
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
println!("Configuration Discovery Example\n");
|
||
|
|
|
||
|
|
// Example 1: Find syntaxis configuration with standard discovery
|
||
|
|
let config = find_config_path("config.toml", None);
|
||
|
|
match config {
|
||
|
|
Some(path) => {
|
||
|
|
println!("✓ Found config at: {}", path.display());
|
||
|
|
println!(" (searched with proper precedence hierarchy)\n");
|
||
|
|
}
|
||
|
|
None => {
|
||
|
|
println!("✗ config.toml not found in standard locations\n");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Example 2: Use explicit config path
|
||
|
|
let explicit_config = std::path::PathBuf::from("/custom/config.toml");
|
||
|
|
let found = find_config_path("config.toml", Some(&explicit_config));
|
||
|
|
match found {
|
||
|
|
Some(path) => println!("✓ Explicit config found at: {}", path.display()),
|
||
|
|
None => println!("✗ Explicit config path does not exist"),
|
||
|
|
}
|
||
|
|
|
||
|
|
println!("\n---");
|
||
|
|
println!("Configuration Search Order (by precedence):");
|
||
|
|
println!("1. Explicit --config path (highest priority)");
|
||
|
|
println!("2. Global: ~/.vapora/config.toml");
|
||
|
|
println!("3. Global: ~/.syntaxis/config.toml");
|
||
|
|
println!("4. Local: ./.vapora/config.toml (takes precedence over .syntaxis/)");
|
||
|
|
println!("5. Local: ./.syntaxis/config.toml");
|
||
|
|
println!("\nThe finder uses the first location that exists.");
|
||
|
|
}
|