1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! Config command handler - manage configuration inheritance
use std::fs;
use crate::cli::ConfigAction;
use crate::team;
/// Handle config subcommands
pub fn run_config(action: &ConfigAction) -> i32 {
match action {
ConfigAction::Show {
file,
resolved,
extends_chain,
output_format,
} => {
if *extends_chain {
// Show the inheritance chain
let base_path = std::path::Path::new(file)
.parent()
.map(|p| p.to_path_buf())
.unwrap_or_else(|| std::env::current_dir().unwrap_or_default());
let mut resolver = team::InheritanceResolver::new().with_base_dir(base_path);
match resolver.resolve(file) {
Ok(_) => {
let trace = resolver.trace();
println!("Extends Chain for {}", file);
println!("========================");
for entry in trace.entries.iter() {
let indent = " ".repeat(entry.depth);
println!("{}↳ {}", indent, entry.source);
}
}
Err(e) => {
eprintln!("Error resolving config: {:?}", e);
return 1;
}
}
return 0;
}
if *resolved {
// Show resolved config with inheritance applied
let base_path = std::path::Path::new(file)
.parent()
.map(|p| p.to_path_buf())
.unwrap_or_else(|| std::env::current_dir().unwrap_or_default());
let mut resolver = team::InheritanceResolver::new().with_base_dir(base_path);
match resolver.resolve(file) {
Ok(extended) => {
match output_format.as_str() {
"json" => {
println!(
"{}",
serde_json::to_string_pretty(&extended).unwrap_or_default()
);
}
"yaml" => {
println!(
"{}",
serde_yaml::to_string(&extended).unwrap_or_default()
);
}
_ => {
// TOML
println!(
"{}",
toml::to_string_pretty(&extended).unwrap_or_default()
);
}
}
}
Err(e) => {
eprintln!("Error resolving config: {:?}", e);
return 1;
}
}
} else {
// Show raw config without inheritance - just read the file
match fs::read_to_string(file) {
Ok(content) => {
match output_format.as_str() {
"json" => {
// Parse TOML then convert to JSON
if let Ok(value) = toml::from_str::<toml::Value>(&content) {
println!(
"{}",
serde_json::to_string_pretty(&value).unwrap_or_default()
);
} else {
eprintln!("Failed to parse config file");
return 1;
}
}
"yaml" => {
// Parse TOML then convert to YAML
if let Ok(value) = toml::from_str::<toml::Value>(&content) {
println!(
"{}",
serde_yaml::to_string(&value).unwrap_or_default()
);
} else {
eprintln!("Failed to parse config file");
return 1;
}
}
_ => {
// Just output the raw TOML
println!("{}", content);
}
}
}
Err(e) => {
eprintln!("Failed to read config file: {}", e);
return 1;
}
}
}
}
ConfigAction::Refresh { file, force } => {
let base_path = std::path::Path::new(file)
.parent()
.map(|p| p.to_path_buf())
.unwrap_or_else(|| std::env::current_dir().unwrap_or_default());
let mut resolver = team::InheritanceResolver::new().with_base_dir(base_path);
if *force {
// Clear cache for this config's dependencies
let _cache = team::ConfigCache::new();
println!("Clearing config cache...");
// Note: We'd need to implement cache clearing in ConfigCache
// For now, just re-resolve which will refresh stale entries
}
println!("Resolving config from {}...", file);
match resolver.resolve(file) {
Ok(_extended) => {
let trace = resolver.trace();
println!("Config resolved successfully.");
println!(" Sources: {}", trace.entries.len());
for entry in &trace.entries {
println!(" - {}", entry.source);
}
}
Err(e) => {
eprintln!("Error resolving config: {:?}", e);
return 1;
}
}
}
}
0
}