2015-12-08 02:42:08 +00:00
|
|
|
#![crate_name = "uu_uname"]
|
2014-04-02 00:13:07 +00:00
|
|
|
|
2016-08-19 19:57:26 +00:00
|
|
|
// This file is part of the uutils coreutils package.
|
|
|
|
//
|
|
|
|
// (c) Joao Oliveira <joaoxsouls@gmail.com>
|
|
|
|
// (c) Jian Zeng <anonymousknight96 AT gmail.com>
|
|
|
|
//
|
|
|
|
// For the full copyright and license information, please view the LICENSE
|
|
|
|
// file that was distributed with this source code.
|
|
|
|
//
|
2014-04-02 00:13:07 +00:00
|
|
|
|
2016-08-19 19:57:26 +00:00
|
|
|
// last synced with: uname (GNU coreutils) 8.21
|
2014-04-02 00:13:07 +00:00
|
|
|
|
2015-11-24 01:00:51 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate uucore;
|
2017-12-22 18:27:38 +00:00
|
|
|
extern crate clap;
|
|
|
|
|
|
|
|
use clap::{Arg, App};
|
2016-08-19 19:57:26 +00:00
|
|
|
use uucore::utsname::Uname;
|
2015-11-24 01:00:51 +00:00
|
|
|
|
2018-03-05 10:53:08 +00:00
|
|
|
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
|
|
|
const ABOUT: &'static str = "Print certain system information. With no OPTION, same as -s.";
|
2017-12-22 18:27:38 +00:00
|
|
|
|
2018-03-05 10:53:08 +00:00
|
|
|
const OPT_ALL: &'static str = "all";
|
|
|
|
const OPT_KERNELNAME: &'static str = "kernel-name";
|
|
|
|
const OPT_NODENAME: &'static str = "nodename";
|
|
|
|
const OPT_KERNELVERSION: &'static str = "kernel-version";
|
|
|
|
const OPT_KERNELRELEASE: &'static str = "kernel-release";
|
|
|
|
const OPT_MACHINE: &'static str = "machine";
|
2017-12-22 18:27:38 +00:00
|
|
|
|
|
|
|
//FIXME: unimplemented options
|
2018-03-05 10:53:08 +00:00
|
|
|
//const OPT_PROCESSOR: &'static str = "processor";
|
|
|
|
//const OPT_HWPLATFORM: &'static str = "hardware-platform";
|
|
|
|
const OPT_OS: &'static str = "operating-system";
|
2014-04-02 00:13:07 +00:00
|
|
|
|
2016-08-19 19:57:26 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
2018-03-05 10:53:08 +00:00
|
|
|
const HOST_OS: &'static str = "GNU/Linux";
|
2016-08-19 19:57:26 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
2018-03-05 10:53:08 +00:00
|
|
|
const HOST_OS: &'static str = "Windows NT";
|
2016-08-19 19:57:26 +00:00
|
|
|
#[cfg(target_os = "freebsd")]
|
2018-03-05 10:53:08 +00:00
|
|
|
const HOST_OS: &'static str = "FreeBSD";
|
2016-08-19 19:57:26 +00:00
|
|
|
#[cfg(target_os = "openbsd")]
|
2018-03-05 10:53:08 +00:00
|
|
|
const HOST_OS: &'static str = "OpenBSD";
|
2016-08-19 19:57:26 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
2018-03-05 10:53:08 +00:00
|
|
|
const HOST_OS: &'static str = "Darwin";
|
2016-11-24 22:30:03 +00:00
|
|
|
#[cfg(target_os = "fuchsia")]
|
2018-03-05 10:53:08 +00:00
|
|
|
const HOST_OS: &'static str = "Fuchsia";
|
|
|
|
#[cfg(target_os = "redox")]
|
|
|
|
const HOST_OS: &'static str = "Redox";
|
2014-04-02 00:13:07 +00:00
|
|
|
|
2015-02-06 13:48:07 +00:00
|
|
|
pub fn uumain(args: Vec<String>) -> i32 {
|
2015-05-21 18:42:42 +00:00
|
|
|
|
2017-12-22 18:27:38 +00:00
|
|
|
let usage = format!("{} [OPTION]...", executable!());
|
|
|
|
let matches = App::new(executable!())
|
|
|
|
.version(VERSION)
|
|
|
|
.about(ABOUT)
|
|
|
|
.usage(&usage[..])
|
|
|
|
.arg(Arg::with_name(OPT_ALL)
|
|
|
|
.short("a")
|
|
|
|
.long(OPT_ALL)
|
|
|
|
.help("Behave as though all of the options -mnrsv were specified."))
|
|
|
|
.arg(Arg::with_name(OPT_KERNELNAME)
|
|
|
|
.short("s")
|
|
|
|
.long(OPT_KERNELNAME)
|
|
|
|
.alias("sysname") // Obsolescent option in GNU uname
|
2017-12-27 10:57:06 +00:00
|
|
|
.help("print the operating system name."))
|
2017-12-22 18:27:38 +00:00
|
|
|
.arg(Arg::with_name(OPT_NODENAME)
|
|
|
|
.short("n")
|
|
|
|
.long(OPT_NODENAME)
|
|
|
|
.help("print the nodename (the nodename may be a name that the system is known by to a communications network)."))
|
|
|
|
.arg(Arg::with_name(OPT_KERNELRELEASE)
|
|
|
|
.short("r")
|
|
|
|
.long(OPT_KERNELRELEASE)
|
|
|
|
.alias("release") // Obsolescent option in GNU uname
|
|
|
|
.help("print the operating system release."))
|
|
|
|
.arg(Arg::with_name(OPT_KERNELVERSION)
|
|
|
|
.short("v")
|
|
|
|
.long(OPT_KERNELVERSION)
|
|
|
|
.help("print the operating system version."))
|
2015-05-21 18:42:42 +00:00
|
|
|
|
2017-12-22 18:27:38 +00:00
|
|
|
//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_MACHINE)
|
|
|
|
.short("m")
|
|
|
|
.long(OPT_MACHINE)
|
|
|
|
.help("print the machine hardware name."))
|
|
|
|
.get_matches_from(&args);
|
2016-08-19 19:57:26 +00:00
|
|
|
|
|
|
|
let argc = args.len();
|
2018-03-05 01:58:16 +00:00
|
|
|
let uname = return_if_err!(1, Uname::new());
|
2014-05-25 09:20:52 +00:00
|
|
|
let mut output = String::new();
|
2017-12-22 18:27:38 +00:00
|
|
|
|
|
|
|
if matches.is_present(OPT_KERNELNAME) || matches.is_present(OPT_ALL) || argc == 1 {
|
2016-08-19 19:57:26 +00:00
|
|
|
output.push_str(uname.sysname().as_ref());
|
|
|
|
output.push_str(" ");
|
2014-04-02 00:13:07 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 18:27:38 +00:00
|
|
|
if matches.is_present(OPT_NODENAME) || matches.is_present(OPT_ALL) {
|
2016-08-19 19:57:26 +00:00
|
|
|
output.push_str(uname.nodename().as_ref());
|
2014-04-03 02:25:58 +00:00
|
|
|
output.push_str(" ");
|
2014-04-02 00:13:07 +00:00
|
|
|
}
|
2017-12-22 18:27:38 +00:00
|
|
|
if matches.is_present(OPT_KERNELRELEASE) || matches.is_present(OPT_ALL) {
|
2016-08-19 19:57:26 +00:00
|
|
|
output.push_str(uname.release().as_ref());
|
2014-04-03 02:25:58 +00:00
|
|
|
output.push_str(" ");
|
2014-04-02 00:13:07 +00:00
|
|
|
}
|
2017-12-22 18:27:38 +00:00
|
|
|
if matches.is_present(OPT_KERNELVERSION) || matches.is_present(OPT_ALL) {
|
2016-08-19 19:57:26 +00:00
|
|
|
output.push_str(uname.version().as_ref());
|
2014-04-03 02:25:58 +00:00
|
|
|
output.push_str(" ");
|
2014-04-02 00:13:07 +00:00
|
|
|
}
|
2017-12-22 18:27:38 +00:00
|
|
|
if matches.is_present(OPT_MACHINE) || matches.is_present(OPT_ALL) {
|
2016-08-19 19:57:26 +00:00
|
|
|
output.push_str(uname.machine().as_ref());
|
|
|
|
output.push_str(" ");
|
|
|
|
}
|
2017-12-22 18:27:38 +00:00
|
|
|
if matches.is_present(OPT_OS) || matches.is_present(OPT_ALL) {
|
2016-08-19 19:57:26 +00:00
|
|
|
output.push_str(HOST_OS);
|
2014-04-03 02:25:58 +00:00
|
|
|
output.push_str(" ");
|
2014-04-02 00:13:07 +00:00
|
|
|
}
|
2015-04-28 02:06:19 +00:00
|
|
|
println!("{}", output.trim());
|
2014-06-08 07:56:37 +00:00
|
|
|
|
2014-06-12 04:41:53 +00:00
|
|
|
0
|
2014-04-02 00:13:07 +00:00
|
|
|
}
|