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;
|
2016-08-19 19:57:26 +00:00
|
|
|
use uucore::utsname::Uname;
|
2015-11-24 01:00:51 +00:00
|
|
|
|
2016-08-19 19:57:26 +00:00
|
|
|
static SYNTAX: &'static str = "[OPTION]...";
|
|
|
|
static SUMMARY: &'static str = "Print certain system information. With no OPTION, same as -s.";
|
2014-04-02 00:13:07 +00:00
|
|
|
|
2016-08-19 19:57:26 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
static HOST_OS: &'static str = "GNU/Linux";
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
static HOST_OS: &'static str = "Windows NT";
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
static HOST_OS: &'static str = "FreeBSD";
|
|
|
|
#[cfg(target_os = "openbsd")]
|
|
|
|
static HOST_OS: &'static str = "OpenBSD";
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
static HOST_OS: &'static str = "Darwin";
|
2014-04-02 00:13:07 +00:00
|
|
|
|
2015-02-06 13:48:07 +00:00
|
|
|
pub fn uumain(args: Vec<String>) -> i32 {
|
2016-08-19 19:57:26 +00:00
|
|
|
let mut opts = new_coreopts!(SYNTAX, SUMMARY, "");
|
2015-05-21 18:42:42 +00:00
|
|
|
|
2016-08-19 19:57:26 +00:00
|
|
|
opts.optflag("a",
|
|
|
|
"all",
|
|
|
|
"Behave as though all of the options -mnrsv were specified.");
|
2015-05-21 18:42:42 +00:00
|
|
|
opts.optflag("s", "sysname", "print the operating system name.");
|
2016-08-19 19:57:26 +00:00
|
|
|
opts.optflag("n", "nodename", "print the nodename (the nodename may be a name that the system is known by to a communications network).");
|
|
|
|
opts.optflag("r", "kernel-release", "print the operating system release.");
|
|
|
|
opts.optflag("v", "kernel-version", "print the operating system version.");
|
|
|
|
opts.optflag("m", "machine", "print the machine hardware name.");
|
2015-05-21 18:42:42 +00:00
|
|
|
|
2016-08-19 19:57:26 +00:00
|
|
|
// FIXME: Unimplemented
|
|
|
|
// opts.optflag("p", "processor", "print the machine processor architecture name.");
|
|
|
|
// opts.optflag("i", "hardware-platform", "print the hardware platform.");
|
|
|
|
|
|
|
|
opts.optflag("o", "operating-system", "print the operating system");
|
|
|
|
let argc = args.len();
|
|
|
|
let matches = opts.parse(args);
|
|
|
|
let uname = Uname::new();
|
2014-05-25 09:20:52 +00:00
|
|
|
let mut output = String::new();
|
2016-08-19 19:57:26 +00:00
|
|
|
if matches.opt_present("sysname") || matches.opt_present("all") || argc == 1 {
|
|
|
|
output.push_str(uname.sysname().as_ref());
|
|
|
|
output.push_str(" ");
|
2014-04-02 00:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if matches.opt_present("nodename") || matches.opt_present("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
|
|
|
}
|
2016-08-19 19:57:26 +00:00
|
|
|
if matches.opt_present("kernel-release") || matches.opt_present("all") {
|
|
|
|
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
|
|
|
}
|
2016-08-19 19:57:26 +00:00
|
|
|
if matches.opt_present("kernel-version") || matches.opt_present("all") {
|
|
|
|
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
|
|
|
}
|
|
|
|
if matches.opt_present("machine") || matches.opt_present("all") {
|
2016-08-19 19:57:26 +00:00
|
|
|
output.push_str(uname.machine().as_ref());
|
|
|
|
output.push_str(" ");
|
|
|
|
}
|
|
|
|
if matches.opt_present("operating-system") || matches.opt_present("all") {
|
|
|
|
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
|
|
|
}
|