From 672c43596893d97941dfae1a9f886a2411d58a67 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Tue, 30 Apr 2024 17:14:35 +0800 Subject: [PATCH 1/2] Added architecture information display --- cli/src/main.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 823ec6d2..894adf58 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -23,6 +23,9 @@ struct Options { /// Show OS bitness. #[clap(short, long)] bitness: bool, + /// Show OS arch. + #[clap(short = 'A', long = "Arch")] + architecture: bool, } fn main() { @@ -31,16 +34,19 @@ fn main() { let options = Options::parse(); let info = os_info::get(); - if options.all || !(options.type_ || options.os_version || options.bitness) { - if options.type_ || options.os_version || options.bitness { + if options.all + || !(options.type_ || options.os_version || options.bitness || options.architecture) + { + if options.type_ || options.os_version || options.bitness || options.architecture { warn!("--all supersedes all other options"); } println!( - "OS information:\nType: {}\nVersion: {}\nBitness: {}", + "OS information:\nType: {}\nVersion: {}\nBitness: {} \narchitecture:{}", info.os_type(), info.version(), - info.bitness() + info.bitness(), + info.architecture().unwrap() ); } else { if options.type_ { @@ -54,5 +60,9 @@ fn main() { if options.bitness { println!("OS bitness: {}", info.bitness()); } + + if options.architecture { + println!("OS architecture: {}", info.architecture().unwrap()); + } } } From 06fe7a8b1508122bf30279bd2814d760cff65822 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Wed, 8 May 2024 09:51:40 +0800 Subject: [PATCH 2/2] Change test case function name 'Uos' to' uos' --- os_info/src/linux/lsb_release.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/os_info/src/linux/lsb_release.rs b/os_info/src/linux/lsb_release.rs index 10eb33b2..cfe12427 100644 --- a/os_info/src/linux/lsb_release.rs +++ b/os_info/src/linux/lsb_release.rs @@ -66,7 +66,7 @@ struct LsbRelease { fn retrieve() -> Option { match Command::new("lsb_release").arg("-a").output() { Ok(output) => { - trace!("lsb_release command returned {:?}", output); + trace!("lsb_release command returned {:?}", output); //日志信息 Some(parse(&String::from_utf8_lossy(&output.stdout))) } Err(e) => { @@ -76,6 +76,7 @@ fn retrieve() -> Option { } } +// 解析 fn parse(output: &str) -> LsbRelease { trace!("Trying to parse {:?}", output); @@ -188,21 +189,15 @@ mod tests { #[test] fn nobara() { let parse_results = parse(nobara_file()); - assert_eq!( - parse_results.distribution, - Some("NobaraLinux".to_string()) - ); + assert_eq!(parse_results.distribution, Some("NobaraLinux".to_string())); assert_eq!(parse_results.version, Some("39".to_string())); assert_eq!(parse_results.codename, None); } #[test] - fn Uos() { + fn uos() { let parse_results = parse(uos_file()); - assert_eq!( - parse_results.distribution, - Some("uos".to_string()) - ); + assert_eq!(parse_results.distribution, Some("uos".to_string())); assert_eq!(parse_results.version, Some("20".to_string())); assert_eq!(parse_results.codename, Some("eagle".to_string())); }