已合并
feat: diagnose configured sources and offline download URLs #43
KarliosQu创建于 28 天前
feat: diagnose configured sources and offline download URLs #43
已合并
共 7 个文件变更+811-4
| @@ -1102,7 +1102,11 @@ fn cmd_doctor(args: &[String]) -> Result<(), String> { | |||
| 1102 | } | 1102 | } |
| 1103 | index += 1; | 1103 | index += 1; |
| 1104 | } | 1104 | } |
| 1105 | + let activity = (!json).then(|| { | ||
| 1106 | + ui::progress::ActivityStatus::new("Doctor", "Checking system and configured sources") | ||
| 1107 | + }); | ||
| 1105 | let checks = doctor_checks(config.as_deref()); | 1108 | let checks = doctor_checks(config.as_deref()); |
| 1109 | + drop(activity); | ||
| 1106 | if json { | 1110 | if json { |
| 1107 | let mut diagnostic = serde_json::to_value(&checks).map_err(|error| error.to_string())?; | 1111 | let mut diagnostic = serde_json::to_value(&checks).map_err(|error| error.to_string())?; |
| 1108 | crate::redaction::redact_diagnostic_json(&mut diagnostic); | 1112 | crate::redaction::redact_diagnostic_json(&mut diagnostic); |
| @@ -1122,7 +1126,12 @@ fn cmd_doctor(args: &[String]) -> Result<(), String> { | |||
| 1122 | "error" => StatusKind::Error, | 1126 | "error" => StatusKind::Error, |
| 1123 | _ => StatusKind::Info, | 1127 | _ => StatusKind::Info, |
| 1124 | }; | 1128 | }; |
| 1125 | - document = document.status_item(check.id, check.summary, kind); | 1129 | + let label = if check.id.starts_with("network.source.") { |
| 1130 | + "network.source".to_string() | ||
| 1131 | + } else { | ||
| 1132 | + check.id | ||
| 1133 | + }; | ||
| 1134 | + document = document.status_item(label, check.summary, kind); | ||
| 1126 | if let Some(suggestion) = check.suggestion { | 1135 | if let Some(suggestion) = check.suggestion { |
| 1127 | document = document.hint(suggestion); | 1136 | document = document.hint(suggestion); |
| 1128 | } | 1137 | } |
| @@ -138,7 +138,7 @@ const STATUS_CONFIGURATION: &[(&str, &str)] = &[ | |||
| 138 | const STATUS_OUTPUT: &[(&str, &str)] = &[("--format <FORMAT>", "Output format: human or json")]; | 138 | const STATUS_OUTPUT: &[(&str, &str)] = &[("--format <FORMAT>", "Output format: human or json")]; |
| 139 | const DOCTOR_CONFIGURATION: &[(&str, &str)] = &[( | 139 | const DOCTOR_CONFIGURATION: &[(&str, &str)] = &[( |
| 140 | "--config <FILE>", | 140 | "--config <FILE>", |
| 141 | - "Configuration file; defaults to bot-forge.toml", | 141 | + "Configuration to diagnose, including mirrors and offline-file URLs; defaults to bot-forge.toml", |
| 142 | )]; | 142 | )]; |
| 143 | const DOCTOR_OUTPUT: &[(&str, &str)] = &[("--format <FORMAT>", "Output format: human or json")]; | 143 | const DOCTOR_OUTPUT: &[(&str, &str)] = &[("--format <FORMAT>", "Output format: human or json")]; |
| 144 | const EFFECTIVE_CONFIGURATION: &[(&str, &str)] = &[ | 144 | const EFFECTIVE_CONFIGURATION: &[(&str, &str)] = &[ |
| @@ -382,7 +382,11 @@ pub(crate) fn command_help(path: &[&str]) -> Option<CommandHelp> { | |||
| 382 | NO_CHILDREN, | 382 | NO_CHILDREN, |
| 383 | NO_SECTIONS, | 383 | NO_SECTIONS, |
| 384 | ), | 384 | ), |
| 385 | - ["doctor"] => ("Run system diagnostics", NO_CHILDREN, DOCTOR_SECTIONS), | 385 | + ["doctor"] => ( |
| 386 | + "Run system and configured-source diagnostics", | ||
| 387 | + NO_CHILDREN, | ||
| 388 | + DOCTOR_SECTIONS, | ||
| 389 | + ), | ||
| 386 | ["apt-mirror"] => ("Manage APT mirrors", NO_CHILDREN, NO_SECTIONS), | 390 | ["apt-mirror"] => ("Manage APT mirrors", NO_CHILDREN, NO_SECTIONS), |
| 387 | ["apt-mirror", "show"] => ( | 391 | ["apt-mirror", "show"] => ( |
| 388 | "Preview the configured mirror", | 392 | "Preview the configured mirror", |
| @@ -201,6 +201,7 @@ enum CacheCommand { | |||
| 201 | 201 | ||
| 202 | #[derive(Debug, clap::Args)] | 202 | #[derive(Debug, clap::Args)] |
| 203 | struct DoctorArgs { | 203 | struct DoctorArgs { |
| 204 | + /// Diagnose this configuration, including mirrors and offline-file URLs. | ||
| 204 | #[arg(long)] | 205 | #[arg(long)] |
| 205 | config: Option<String>, | 206 | config: Option<String>, |
| 206 | #[arg(long, value_enum)] | 207 | #[arg(long, value_enum)] |
| @@ -176,7 +176,7 @@ mod tests { | |||
| 176 | .iter() | 176 | .iter() |
| 177 | .any(|component| component.id == "cargo-valgrind") | 177 | .any(|component| component.id == "cargo-valgrind") |
| 178 | ); | 178 | ); |
| 179 | - for (id, version) in [("bot-gate", "=1.3.2"), ("bot-metric", "=1.2.2")] { | 179 | + for (id, version) in [("bot-gate", "=1.3.3"), ("bot-metric", "=1.2.3")] { |
| 180 | let component = plan | 180 | let component = plan |
| 181 | .components | 181 | .components |
| 182 | .iter() | 182 | .iter() |
| @@ -61,6 +61,9 @@ pub(crate) fn doctor_checks(explicit_config: Option<&Path>) -> Vec<DiagnosticChe | |||
| 61 | dns_check(), | 61 | dns_check(), |
| 62 | tls_check(), | 62 | tls_check(), |
| 63 | ]); | 63 | ]); |
| 64 | + if let Ok(loaded) = load_config_with_overlays(explicit_config, &[]) { | ||
| 65 | + checks.extend(crate::diagnostics::sources::source_checks(&loaded.document)); | ||
| 66 | + } | ||
| 64 | checks | 67 | checks |
| 65 | } | 68 | } |
| 66 | 69 | ||
| @@ -5,5 +5,6 @@ | |||
| 5 | 5 | ||
| 6 | mod checks; | 6 | mod checks; |
| 7 | pub(crate) mod proxy; | 7 | pub(crate) mod proxy; |
| 8 | +mod sources; | ||
| 8 | 9 | ||
| 9 | pub(crate) use crate::diagnostics::checks::doctor_checks; | 10 | pub(crate) use crate::diagnostics::checks::doctor_checks; |