diff --git a/src/analyzer/mod.rs b/src/analyzer/mod.rs index df510c4..37e7d54 100644 --- a/src/analyzer/mod.rs +++ b/src/analyzer/mod.rs @@ -94,6 +94,39 @@ fn list_cves(cli: &Cli) -> crate::Result<()> { fn list_sas(cli: &Cli) -> crate::Result<()> { let avaliable = get_avaliable()?; let severity = Severity::from_str(&cli.severity)?; + let mut _sas = HashSet::new(); + cli.sources.iter().for_each(|id| { _sas.insert(id); }); + + let mut sas = HashSet::new(); + let mut msg = String::new(); + + // 仅针对可用更新 + for (cusa, _) in &avaliable { + // 过滤 + if cusa.severity() < &severity { + continue; + } + + if let Some(_) = _sas.get(&cusa.id) { + let _ = sas.insert(cusa.clone()); + _sas.remove(&cusa.id); + } + } + + for sa in &sas { + if cli.info { + msg = format!("{msg}\n\n{sa:#?}"); + } else { + msg = format!("{msg}\n{}", sa.id); + } + } + + if !_sas.is_empty() { + msg = format!("{msg}\n\nUnaffected SAs:\n{_sas:#?}") + } + + println!("{msg}"); + Ok(()) }