Craft Anything: understand how any software works, and craft your own.
Rust
Setup and the doctor read a client's other names from one table (#184)
BFlat202264255407
diff --git a/crates/setup/src/clients.rs b/crates/setup/src/clients.rsindex a62a70e5..aa991a83 100644--- a/crates/setup/src/clients.rs+++ b/crates/setup/src/clients.rs@@ -163,7 +163,16 @@ pub struct Client {pub manual: Option<&'static str>,}+/// Other names people use for a client (its program's name).+const ALIASES: &[(&str, &str)] = &[("agy", "antigravity")];+impl Client {+ /// Whether `name` (an id, `-` or `_`, or an alias) means this client.+ pub fn is(&self, name: &str) -> bool {+ let name = name.replace('-', "_");+ name == self.id || ALIASES.iter().any(|(alias, id)| name == *alias && *id == self.id)+ }+pub fn detected(&self) -> bool {self.config.exists() || self.markers.iter().any(|m| m.exists())}@@ -440,6 +449,16 @@ mod tests {assert!(cs.iter().all(|c| c.config.starts_with("/home/u") || c.format == Format::Manual || host.os == Os::Windows));}+ #[test]+ fn a_client_is_named_by_id_dashes_or_its_program() {+ let cs = clients(&Host::with_home("/home/u"));+ let named = |n: &str| cs.iter().filter(|c| c.is(n)).map(|c| c.id).collect::<Vec<_>>();+ assert_eq!(named("antigravity"), ["antigravity"]);+ assert_eq!(named("agy"), ["antigravity"]);+ assert_eq!(named("kimi-code"), ["kimi_code"]);+ assert!(named("nope").is_empty());+ }+#[test]fn newer_clients_have_their_config_and_skill_folders() {let host = Host::with_home("/home/u");diff --git a/crates/setup/src/doctor.rs b/crates/setup/src/doctor.rsindex 5aa72e8a..b098df60 100644--- a/crates/setup/src/doctor.rs+++ b/crates/setup/src/doctor.rs@@ -89,19 +89,7 @@ pub fn doctor(host: &Host, req: &DoctorRequest) -> DoctorReport {// Registrations.let all = clients(host);let explicit = !req.clients.is_empty();- let selected: Vec<_> = all- .iter()- .filter(|c| {- if explicit {- req.clients.iter().any(|id| {- let norm = id.replace('-', "_");- norm == c.id || (norm == "agy" && c.id == "antigravity")- })- } else {- c.detected()- }- })- .collect();+ let selected: Vec<_> = all.iter().filter(|c| if explicit { req.clients.iter().any(|id| c.is(id)) } else { c.detected() }).collect();let mut skill_dirs: Vec<PathBuf> = Vec::new();for c in &selected {let name = format!("registration:{}", c.id);diff --git a/crates/setup/src/plan.rs b/crates/setup/src/plan.rsindex c07d5724..e819c26d 100644--- a/crates/setup/src/plan.rs+++ b/crates/setup/src/plan.rs@@ -194,8 +194,7 @@ pub fn plan(host: &Host, req: &PlanRequest) -> Result<Plan, ToolError> {let selected: Vec<&Client> = if !req.clients.is_empty() {let mut v = Vec::new();for id in &req.clients {- let id_norm = id.replace('-', "_");- match all.iter().find(|c| c.id == id_norm || (id_norm == "agy" && c.id == "antigravity")) {+ match all.iter().find(|c| c.is(id)) {Some(c) => v.push(c),None => {let ids: Vec<&str> = all.iter().map(|c| c.id).collect();