Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add architecture information display #382

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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