Skip to content

Commit

Permalink
Merge pull request #382 from WangMengabc/master
Browse files Browse the repository at this point in the history
Add   architecture information display
  • Loading branch information
stanislav-tkach committed May 19, 2024
2 parents ab7fc07 + 06fe7a8 commit 782e756
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
18 changes: 14 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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_ {
Expand All @@ -54,5 +60,9 @@ fn main() {
if options.bitness {
println!("OS bitness: {}", info.bitness());
}

if options.architecture {
println!("OS architecture: {}", info.architecture().unwrap());
}
}
}
15 changes: 5 additions & 10 deletions os_info/src/linux/lsb_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct LsbRelease {
fn retrieve() -> Option<LsbRelease> {
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) => {
Expand All @@ -76,6 +76,7 @@ fn retrieve() -> Option<LsbRelease> {
}
}

// 解析
fn parse(output: &str) -> LsbRelease {
trace!("Trying to parse {:?}", output);

Expand Down Expand Up @@ -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()));
}
Expand Down

0 comments on commit 782e756

Please sign in to comment.