mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #4279 from rivy/up.uname
change/uname ~ update and revise
This commit is contained in:
commit
afbe850115
4 changed files with 45 additions and 56 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1633,9 +1633,9 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
|||
|
||||
[[package]]
|
||||
name = "platform-info"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4278b2b54a23c9a91d5bae9b09e21d566f8b23890491951160b05d64f29d1d8b"
|
||||
checksum = "4e7c23cfae725ae06d9e43010153fa77bdfa8c827bf08fe4beeb2a3514e6be12"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
|
|
|
@ -15,7 +15,7 @@ edition = "2021"
|
|||
path = "src/uname.rs"
|
||||
|
||||
[dependencies]
|
||||
platform-info = "1.0.1"
|
||||
platform-info = "1.0.2"
|
||||
clap = { version = "4.0", features = ["wrap_help", "cargo"] }
|
||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
// last synced with: uname (GNU coreutils) 8.21
|
||||
|
||||
// spell-checker:ignore (ToDO) nodename kernelname kernelrelease kernelversion sysname hwplatform mnrsv
|
||||
// spell-checker:ignore (API) nodename osname sysname (options) mnrsv mnrsvo
|
||||
|
||||
use clap::{crate_version, Arg, ArgAction, Command};
|
||||
use platform_info::*;
|
||||
|
@ -23,37 +23,16 @@ const USAGE: &str = "{} [OPTION]...";
|
|||
|
||||
pub mod options {
|
||||
pub static ALL: &str = "all";
|
||||
pub static KERNELNAME: &str = "kernel-name";
|
||||
pub static KERNEL_NAME: &str = "kernel-name";
|
||||
pub static NODENAME: &str = "nodename";
|
||||
pub static KERNELVERSION: &str = "kernel-version";
|
||||
pub static KERNELRELEASE: &str = "kernel-release";
|
||||
pub static KERNEL_VERSION: &str = "kernel-version";
|
||||
pub static KERNEL_RELEASE: &str = "kernel-release";
|
||||
pub static MACHINE: &str = "machine";
|
||||
pub static PROCESSOR: &str = "processor";
|
||||
pub static HWPLATFORM: &str = "hardware-platform";
|
||||
pub static HARDWARE_PLATFORM: &str = "hardware-platform";
|
||||
pub static OS: &str = "operating-system";
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "")))]
|
||||
const HOST_OS: &str = "GNU/Linux";
|
||||
#[cfg(all(target_os = "linux", not(any(target_env = "gnu", target_env = ""))))]
|
||||
const HOST_OS: &str = "Linux";
|
||||
#[cfg(target_os = "android")]
|
||||
const HOST_OS: &str = "Android";
|
||||
#[cfg(target_os = "windows")]
|
||||
const HOST_OS: &str = "Windows NT";
|
||||
#[cfg(target_os = "freebsd")]
|
||||
const HOST_OS: &str = "FreeBSD";
|
||||
#[cfg(target_os = "netbsd")]
|
||||
const HOST_OS: &str = "NetBSD";
|
||||
#[cfg(target_os = "openbsd")]
|
||||
const HOST_OS: &str = "OpenBSD";
|
||||
#[cfg(target_vendor = "apple")]
|
||||
const HOST_OS: &str = "Darwin";
|
||||
#[cfg(target_os = "fuchsia")]
|
||||
const HOST_OS: &str = "Fuchsia";
|
||||
#[cfg(target_os = "redox")]
|
||||
const HOST_OS: &str = "Redox";
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().try_get_matches_from(args)?;
|
||||
|
@ -63,41 +42,42 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let mut output = String::new();
|
||||
|
||||
let all = matches.get_flag(options::ALL);
|
||||
let kernelname = matches.get_flag(options::KERNELNAME);
|
||||
let kernel_name = matches.get_flag(options::KERNEL_NAME);
|
||||
let nodename = matches.get_flag(options::NODENAME);
|
||||
let kernelrelease = matches.get_flag(options::KERNELRELEASE);
|
||||
let kernelversion = matches.get_flag(options::KERNELVERSION);
|
||||
let kernel_release = matches.get_flag(options::KERNEL_RELEASE);
|
||||
let kernel_version = matches.get_flag(options::KERNEL_VERSION);
|
||||
let machine = matches.get_flag(options::MACHINE);
|
||||
let processor = matches.get_flag(options::PROCESSOR);
|
||||
let hwplatform = matches.get_flag(options::HWPLATFORM);
|
||||
let hardware_platform = matches.get_flag(options::HARDWARE_PLATFORM);
|
||||
let os = matches.get_flag(options::OS);
|
||||
|
||||
let none = !(all
|
||||
|| kernelname
|
||||
|| kernel_name
|
||||
|| nodename
|
||||
|| kernelrelease
|
||||
|| kernelversion
|
||||
|| kernel_release
|
||||
|| kernel_version
|
||||
|| machine
|
||||
|| os
|
||||
|| processor
|
||||
|| hwplatform);
|
||||
|| hardware_platform);
|
||||
|
||||
if kernelname || all || none {
|
||||
if kernel_name || all || none {
|
||||
output.push_str(&uname.sysname());
|
||||
output.push(' ');
|
||||
}
|
||||
|
||||
if nodename || all {
|
||||
output.push_str(&uname.nodename());
|
||||
// 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(' ');
|
||||
}
|
||||
|
||||
if kernelrelease || all {
|
||||
if kernel_release || all {
|
||||
output.push_str(&uname.release());
|
||||
output.push(' ');
|
||||
}
|
||||
|
||||
if kernelversion || all {
|
||||
if kernel_version || all {
|
||||
output.push_str(&uname.version());
|
||||
output.push(' ');
|
||||
}
|
||||
|
@ -108,7 +88,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
}
|
||||
|
||||
if os || all {
|
||||
output.push_str(HOST_OS);
|
||||
output.push_str(&uname.osname());
|
||||
output.push(' ');
|
||||
}
|
||||
|
||||
|
@ -121,7 +101,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
// This option is unsupported on modern Linux systems
|
||||
// See: https://lists.gnu.org/archive/html/bug-coreutils/2005-09/msg00063.html
|
||||
if hwplatform {
|
||||
if hardware_platform {
|
||||
output.push_str("unknown");
|
||||
output.push(' ');
|
||||
}
|
||||
|
@ -141,13 +121,13 @@ pub fn uu_app() -> Command {
|
|||
Arg::new(options::ALL)
|
||||
.short('a')
|
||||
.long(options::ALL)
|
||||
.help("Behave as though all of the options -mnrsv were specified.")
|
||||
.help("Behave as though all of the options -mnrsvo were specified.")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::KERNELNAME)
|
||||
Arg::new(options::KERNEL_NAME)
|
||||
.short('s')
|
||||
.long(options::KERNELNAME)
|
||||
.long(options::KERNEL_NAME)
|
||||
.alias("sysname") // Obsolescent option in GNU uname
|
||||
.help("print the kernel name.")
|
||||
.action(ArgAction::SetTrue),
|
||||
|
@ -163,17 +143,17 @@ pub fn uu_app() -> Command {
|
|||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::KERNELRELEASE)
|
||||
Arg::new(options::KERNEL_RELEASE)
|
||||
.short('r')
|
||||
.long(options::KERNELRELEASE)
|
||||
.long(options::KERNEL_RELEASE)
|
||||
.alias("release") // Obsolescent option in GNU uname
|
||||
.help("print the operating system release.")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::KERNELVERSION)
|
||||
Arg::new(options::KERNEL_VERSION)
|
||||
.short('v')
|
||||
.long(options::KERNELVERSION)
|
||||
.long(options::KERNEL_VERSION)
|
||||
.help("print the operating system version.")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
|
@ -200,9 +180,9 @@ pub fn uu_app() -> Command {
|
|||
.hide(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::HWPLATFORM)
|
||||
Arg::new(options::HARDWARE_PLATFORM)
|
||||
.short('i')
|
||||
.long(options::HWPLATFORM)
|
||||
.long(options::HARDWARE_PLATFORM)
|
||||
.help("print the hardware platform (non-portable)")
|
||||
.action(ArgAction::SetTrue)
|
||||
.hide(true),
|
||||
|
|
|
@ -104,10 +104,11 @@ fn test_uname_operating_system() {
|
|||
.succeeds()
|
||||
.stdout_is("Redox\n");
|
||||
#[cfg(target_os = "windows")]
|
||||
new_ucmd!()
|
||||
.arg("--operating-system")
|
||||
.succeeds()
|
||||
.stdout_is("Windows NT\n");
|
||||
{
|
||||
let result = new_ucmd!().arg("--operating-system").succeeds();
|
||||
println!("{:?}", result.stdout_str());
|
||||
assert!(result.stdout_str().starts_with("MS/Windows"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -117,3 +118,11 @@ fn test_uname_help() {
|
|||
.succeeds()
|
||||
.stdout_contains("system information");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uname_output_for_invisible_chars() {
|
||||
// let re = regex::Regex::new("[^[[:print:]]]").unwrap(); // matches invisible (and emojis)
|
||||
let re = regex::Regex::new("[^[[:print:]]\\p{Other_Symbol}]").unwrap(); // matches invisible (not emojis)
|
||||
let result = new_ucmd!().arg("--all").succeeds();
|
||||
assert_eq!(re.find(result.stdout_str().trim_end()), None);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue