Skip to content

Commit

Permalink
update to platform-info 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed May 27, 2023
1 parent 434bba3 commit 3713d52
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ onig = { version = "~6.4", default-features = false }
ouroboros = "0.15.6"
phf = "0.11.1"
phf_codegen = "0.11.1"
platform-info = "1.0.2"
platform-info = "2.0.1"
quick-error = "2.0.1"
rand = { version = "0.8", features = ["small_rng"] }
rand_core = "0.6"
Expand Down
10 changes: 7 additions & 3 deletions src/uu/arch/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use platform_info::*;

use clap::{crate_version, Command};
use uucore::error::{FromIo, UResult};
use uucore::error::{UResult, USimpleError};
use uucore::{help_about, help_section};

static ABOUT: &str = help_about!("arch.md");
Expand All @@ -19,8 +19,12 @@ static SUMMARY: &str = help_section!("after help", "arch.md");
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uu_app().try_get_matches_from(args)?;

let uts = PlatformInfo::new().map_err_context(|| "cannot get system name".to_string())?;
println!("{}", uts.machine().trim());
let uts = match PlatformInfo::new() {
Ok(x) => x,
Err(_e) => return Err(USimpleError::new(1, "cannot get system name")),
};

println!("{}", uts.machine().to_string_lossy().trim());
Ok(())
}

Expand Down
21 changes: 12 additions & 9 deletions src/uu/uname/src/uname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use clap::{crate_version, Arg, ArgAction, Command};
use platform_info::*;
use uucore::{
error::{FromIo, UResult},
error::{UResult, USimpleError},
format_usage, help_about, help_usage,
};

Expand All @@ -36,8 +36,11 @@ pub mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;

let uname =
PlatformInfo::new().map_err_context(|| "failed to create PlatformInfo".to_string())?;
let uname = match PlatformInfo::new() {
Ok(x) => x,
Err(_e) => return Err(USimpleError::new(1, "cannot get system name")),
};

let mut output = String::new();

let all = matches.get_flag(options::ALL);
Expand All @@ -61,33 +64,33 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|| hardware_platform);

if kernel_name || all || none {
output.push_str(&uname.sysname());
output.push_str(&uname.sysname().to_string_lossy());
output.push(' ');
}

if nodename || all {
// maint: [2023-01-14; rivy] remove `.trim_end_matches('\0')` when platform-info nodename-NUL bug is fixed (see GH:uutils/platform-info/issues/32)
output.push_str(uname.nodename().trim_end_matches('\0'));
output.push_str(uname.nodename().to_string_lossy().trim_end_matches('\0'));
output.push(' ');
}

if kernel_release || all {
output.push_str(&uname.release());
output.push_str(&uname.release().to_string_lossy());
output.push(' ');
}

if kernel_version || all {
output.push_str(&uname.version());
output.push_str(&uname.version().to_string_lossy());
output.push(' ');
}

if machine || all {
output.push_str(&uname.machine());
output.push_str(&uname.machine().to_string_lossy());
output.push(' ');
}

if os || all {
output.push_str(&uname.osname());
output.push_str(&uname.osname().to_string_lossy());
output.push(' ');
}

Expand Down

0 comments on commit 3713d52

Please sign in to comment.