109 lines
3.2 KiB
Rust
109 lines
3.2 KiB
Rust
|
|
//! Example of using the manifest manager functionality.
|
||
|
|
//!
|
||
|
|
//! This example demonstrates how to create, manage, and work with
|
||
|
|
//! manifest files that track installed resources in projects.
|
||
|
|
|
||
|
|
use std::collections::HashMap;
|
||
|
|
use tools_shared::{ConfigEntry, ResourceType};
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
println!("Manifest Manager Example\n");
|
||
|
|
|
||
|
|
// Create example configuration entries
|
||
|
|
let mut configs = HashMap::new();
|
||
|
|
|
||
|
|
// Entry 1: Symlinked resource
|
||
|
|
configs.insert(
|
||
|
|
"justfile".to_string(),
|
||
|
|
ConfigEntry {
|
||
|
|
name: "justfile".to_string(),
|
||
|
|
enabled: true,
|
||
|
|
resource_type: ResourceType::Symlink,
|
||
|
|
path: ".project/justfile".to_string(),
|
||
|
|
modified: false,
|
||
|
|
},
|
||
|
|
);
|
||
|
|
|
||
|
|
println!("✓ Added config: justfile (symlink, unchanged)");
|
||
|
|
|
||
|
|
// Entry 2: Local copy (modified)
|
||
|
|
configs.insert(
|
||
|
|
"lifecycle".to_string(),
|
||
|
|
ConfigEntry {
|
||
|
|
name: "lifecycle".to_string(),
|
||
|
|
enabled: true,
|
||
|
|
resource_type: ResourceType::Local,
|
||
|
|
path: ".project/lifecycle.toml".to_string(),
|
||
|
|
modified: true,
|
||
|
|
},
|
||
|
|
);
|
||
|
|
|
||
|
|
println!("✓ Added config: lifecycle (local copy, modified)");
|
||
|
|
|
||
|
|
// Entry 3: Generated resource
|
||
|
|
configs.insert(
|
||
|
|
"schema".to_string(),
|
||
|
|
ConfigEntry {
|
||
|
|
name: "schema".to_string(),
|
||
|
|
enabled: false,
|
||
|
|
resource_type: ResourceType::Generated,
|
||
|
|
path: ".project/schema.json".to_string(),
|
||
|
|
modified: false,
|
||
|
|
},
|
||
|
|
);
|
||
|
|
|
||
|
|
println!("✓ Added config: schema (generated, disabled)\n");
|
||
|
|
|
||
|
|
// Display manifest information
|
||
|
|
println!("Manifest Summary:");
|
||
|
|
println!(" Total configs: {}", configs.len());
|
||
|
|
println!(
|
||
|
|
" Enabled: {}",
|
||
|
|
configs.values().filter(|c| c.enabled).count()
|
||
|
|
);
|
||
|
|
println!(
|
||
|
|
" Modified: {}",
|
||
|
|
configs.values().filter(|c| c.modified).count()
|
||
|
|
);
|
||
|
|
|
||
|
|
println!("\nConfigurations:");
|
||
|
|
for (key, entry) in &configs {
|
||
|
|
let type_str = match entry.resource_type {
|
||
|
|
ResourceType::Symlink => "symlink",
|
||
|
|
ResourceType::Local => "local",
|
||
|
|
ResourceType::Copy => "copy",
|
||
|
|
ResourceType::Generated => "generated",
|
||
|
|
};
|
||
|
|
|
||
|
|
let status = if entry.enabled {
|
||
|
|
"✓ enabled"
|
||
|
|
} else {
|
||
|
|
"○ disabled"
|
||
|
|
};
|
||
|
|
|
||
|
|
let modified = if entry.modified { " (modified)" } else { "" };
|
||
|
|
|
||
|
|
println!(" - {} ({}) {}{}", key, type_str, status, modified);
|
||
|
|
println!(" → {}", entry.path);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Example: Update an entry
|
||
|
|
if let Some(entry) = configs.get_mut("justfile") {
|
||
|
|
entry.modified = true;
|
||
|
|
println!("\nMarked 'justfile' as modified");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Example: Disable a config
|
||
|
|
if let Some(entry) = configs.get_mut("schema") {
|
||
|
|
entry.enabled = true;
|
||
|
|
println!("Enabled 'schema' configuration");
|
||
|
|
}
|
||
|
|
|
||
|
|
println!("\n---");
|
||
|
|
println!("Resource Types:");
|
||
|
|
println!(" • Symlink - Links to Tools resource, auto-updates");
|
||
|
|
println!(" • Local - Copied from Tools, manually modifiable");
|
||
|
|
println!(" • Copy - One-time copy, standalone");
|
||
|
|
println!(" • Generated - Created from template, can regenerate");
|
||
|
|
}
|