mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
feature(uname): Implement -p & -i (#1649)
Just return 'unknown' for both Closes: #1636
This commit is contained in:
parent
516839e081
commit
068fee2ebd
2 changed files with 67 additions and 11 deletions
|
@ -27,6 +27,8 @@ const OPT_NODENAME: &str = "nodename";
|
||||||
const OPT_KERNELVERSION: &str = "kernel-version";
|
const OPT_KERNELVERSION: &str = "kernel-version";
|
||||||
const OPT_KERNELRELEASE: &str = "kernel-release";
|
const OPT_KERNELRELEASE: &str = "kernel-release";
|
||||||
const OPT_MACHINE: &str = "machine";
|
const OPT_MACHINE: &str = "machine";
|
||||||
|
const OPT_PROCESSOR: &str = "processor";
|
||||||
|
const OPT_HWPLATFORM: &str = "hardware-platform";
|
||||||
|
|
||||||
//FIXME: unimplemented options
|
//FIXME: unimplemented options
|
||||||
//const OPT_PROCESSOR: &'static str = "processor";
|
//const OPT_PROCESSOR: &'static str = "processor";
|
||||||
|
@ -76,20 +78,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.short("v")
|
.short("v")
|
||||||
.long(OPT_KERNELVERSION)
|
.long(OPT_KERNELVERSION)
|
||||||
.help("print the operating system version."))
|
.help("print the operating system version."))
|
||||||
|
.arg(Arg::with_name(OPT_HWPLATFORM)
|
||||||
//FIXME: unimplemented options
|
.short("i")
|
||||||
// .arg(Arg::with_name(OPT_PROCESSOR)
|
.long(OPT_HWPLATFORM)
|
||||||
// .short("p")
|
.help("print the hardware platform (non-portable)"))
|
||||||
// .long(OPT_PROCESSOR)
|
|
||||||
// .help("print the processor type (non-portable)"))
|
|
||||||
// .arg(Arg::with_name(OPT_HWPLATFORM)
|
|
||||||
// .short("i")
|
|
||||||
// .long(OPT_HWPLATFORM)
|
|
||||||
// .help("print the hardware platform (non-portable)"))
|
|
||||||
.arg(Arg::with_name(OPT_MACHINE)
|
.arg(Arg::with_name(OPT_MACHINE)
|
||||||
.short("m")
|
.short("m")
|
||||||
.long(OPT_MACHINE)
|
.long(OPT_MACHINE)
|
||||||
.help("print the machine hardware name."))
|
.help("print the machine hardware name."))
|
||||||
|
.arg(Arg::with_name(OPT_PROCESSOR)
|
||||||
|
.short("p")
|
||||||
|
.long(OPT_PROCESSOR)
|
||||||
|
.help("print the processor type (non-portable)"))
|
||||||
.arg(Arg::with_name(OPT_OS)
|
.arg(Arg::with_name(OPT_OS)
|
||||||
.short("o")
|
.short("o")
|
||||||
.long(OPT_OS)
|
.long(OPT_OS)
|
||||||
|
@ -105,9 +105,19 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let kernelrelease = matches.is_present(OPT_KERNELRELEASE);
|
let kernelrelease = matches.is_present(OPT_KERNELRELEASE);
|
||||||
let kernelversion = matches.is_present(OPT_KERNELVERSION);
|
let kernelversion = matches.is_present(OPT_KERNELVERSION);
|
||||||
let machine = matches.is_present(OPT_MACHINE);
|
let machine = matches.is_present(OPT_MACHINE);
|
||||||
|
let processor = matches.is_present(OPT_PROCESSOR);
|
||||||
|
let hwplatform = matches.is_present(OPT_HWPLATFORM);
|
||||||
let os = matches.is_present(OPT_OS);
|
let os = matches.is_present(OPT_OS);
|
||||||
|
|
||||||
let none = !(all || kernelname || nodename || kernelrelease || kernelversion || machine || os);
|
let none = !(all
|
||||||
|
|| kernelname
|
||||||
|
|| nodename
|
||||||
|
|| kernelrelease
|
||||||
|
|| kernelversion
|
||||||
|
|| machine
|
||||||
|
|| os
|
||||||
|
|| processor
|
||||||
|
|| hwplatform);
|
||||||
|
|
||||||
if kernelname || all || none {
|
if kernelname || all || none {
|
||||||
output.push_str(&uname.sysname());
|
output.push_str(&uname.sysname());
|
||||||
|
@ -130,6 +140,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
output.push_str(&uname.machine());
|
output.push_str(&uname.machine());
|
||||||
output.push(' ');
|
output.push(' ');
|
||||||
}
|
}
|
||||||
|
if processor || all {
|
||||||
|
// According to https://stackoverflow.com/posts/394271/revisions
|
||||||
|
// Most of the time, it returns unknown
|
||||||
|
output.push_str("unknown");
|
||||||
|
output.push(' ');
|
||||||
|
}
|
||||||
|
if hwplatform || all {
|
||||||
|
// According to https://lists.gnu.org/archive/html/bug-coreutils/2005-09/msg00063.html
|
||||||
|
// Most of the time, it returns unknown
|
||||||
|
output.push_str("unknown");
|
||||||
|
output.push(' ');
|
||||||
|
}
|
||||||
if os || all {
|
if os || all {
|
||||||
output.push_str(HOST_OS);
|
output.push_str(HOST_OS);
|
||||||
output.push(' ');
|
output.push(' ');
|
||||||
|
|
|
@ -16,6 +16,40 @@ fn test_uname_name() {
|
||||||
assert!(result.success);
|
assert!(result.success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_uname_processor() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
|
let result = ucmd.arg("-p").run();
|
||||||
|
assert!(result.success);
|
||||||
|
assert_eq!(result.stdout.trim_end(), "unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_uname_hwplatform() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
|
let result = ucmd.arg("-i").run();
|
||||||
|
assert!(result.success);
|
||||||
|
assert_eq!(result.stdout.trim_end(), "unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_uname_machine() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
|
let result = ucmd.arg("-m").run();
|
||||||
|
assert!(result.success);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_uname_kernel_version() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
|
let result = ucmd.arg("-v").run();
|
||||||
|
assert!(result.success);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_uname_kernel() {
|
fn test_uname_kernel() {
|
||||||
let (_, mut ucmd) = at_and_ucmd!();
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue