1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

feature(uname): Implement -p & -i (#1649)

Just return 'unknown' for both

Closes: #1636
This commit is contained in:
Sylvestre Ledru 2020-12-11 22:46:36 +01:00 committed by GitHub
parent 516839e081
commit 068fee2ebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 11 deletions

View file

@ -27,6 +27,8 @@ const OPT_NODENAME: &str = "nodename";
const OPT_KERNELVERSION: &str = "kernel-version";
const OPT_KERNELRELEASE: &str = "kernel-release";
const OPT_MACHINE: &str = "machine";
const OPT_PROCESSOR: &str = "processor";
const OPT_HWPLATFORM: &str = "hardware-platform";
//FIXME: unimplemented options
//const OPT_PROCESSOR: &'static str = "processor";
@ -76,20 +78,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.short("v")
.long(OPT_KERNELVERSION)
.help("print the operating system version."))
//FIXME: unimplemented options
// .arg(Arg::with_name(OPT_PROCESSOR)
// .short("p")
// .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_HWPLATFORM)
.short("i")
.long(OPT_HWPLATFORM)
.help("print the hardware platform (non-portable)"))
.arg(Arg::with_name(OPT_MACHINE)
.short("m")
.long(OPT_MACHINE)
.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)
.short("o")
.long(OPT_OS)
@ -105,9 +105,19 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let kernelrelease = matches.is_present(OPT_KERNELRELEASE);
let kernelversion = matches.is_present(OPT_KERNELVERSION);
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 none = !(all || kernelname || nodename || kernelrelease || kernelversion || machine || os);
let none = !(all
|| kernelname
|| nodename
|| kernelrelease
|| kernelversion
|| machine
|| os
|| processor
|| hwplatform);
if kernelname || all || none {
output.push_str(&uname.sysname());
@ -130,6 +140,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
output.push_str(&uname.machine());
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 {
output.push_str(HOST_OS);
output.push(' ');

View file

@ -16,6 +16,40 @@ fn test_uname_name() {
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]
fn test_uname_kernel() {
let (_, mut ucmd) = at_and_ucmd!();