完成:列出所有已发布但未修复的安全公告

Signed-off-by: Jia Chao <jiachao2130@126.com>
This commit is contained in:
Jia Chao 2024-08-06 15:10:43 +08:00
parent 853be957ee
commit 3b9396c500
2 changed files with 32 additions and 9 deletions

View File

@ -3,6 +3,10 @@ name = "cuvat-rs"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "cuvat"
path = "src/main.rs"
[dependencies]
clap = { version = "4.0", features = ["derive"] }
serde = { version = "1", features = ["serde_derive"] }

View File

@ -65,7 +65,10 @@ fn repoter(cli: &Cli) -> crate::Result<()> {
fn summary(cli: &Cli) -> crate::Result<()> {
let avaliable = get_avaliable()?;
let severity = Severity::from_str(&cli.severity)?;
let mut total = 0;
let mut res = vec![0; 5];
let mut lists = vec![vec![]; 5];
let mut msg = String::new();
for (cusa, rpms) in &avaliable {
// 过滤
@ -74,20 +77,36 @@ fn summary(cli: &Cli) -> crate::Result<()> {
}
let pos: usize = cusa.severity().into();
total += 1;
res[pos] += 1;
lists[pos].push(cusa);
}
let msg = format!(
"
{:3}
{:3}
{:3}
{:3}
// 如果需要列出详细的 sa
if cli.list {
msg = format!("当前系统未修复的公告列表(共 {total} 个):\n");
for sas in &lists {
for sa in sas {
msg = format!("{msg}\n{:>4}{}: {:?}", "", sa.id(), sa.severity());
}
}
//msg = format!("{msg}\n\n");
} else {
msg = format!(
"{msg}
{}
{:>3}
{:>3}
{:>3}
{:>3}
",
res[4], res[3], res[2], res[1]
total, res[4], res[3], res[2], res[1]
);
}
println!("{}", msg);
Ok(())
}