mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
arch: use message templates for consistent, original-work error handling
This commit is contained in:
parent
d56389aca0
commit
1bf2c82520
2 changed files with 7 additions and 23 deletions
|
@ -8,7 +8,6 @@ name = "uu_arch"
|
||||||
path = "arch.rs"
|
path = "arch.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "*"
|
|
||||||
libc = "*"
|
libc = "*"
|
||||||
uucore = { path="../uucore" }
|
uucore = { path="../uucore" }
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,12 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate getopts;
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::io::Write;
|
|
||||||
use std::mem::uninitialized;
|
use std::mem::uninitialized;
|
||||||
use uucore::c_types::utsname;
|
use uucore::c_types::utsname;
|
||||||
|
|
||||||
|
@ -44,28 +42,15 @@ static NAME: &'static str = "arch";
|
||||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let mut opts = getopts::Options::new();
|
let mut opts = uucore::coreopts::CoreOptions::new();
|
||||||
|
let usage = opts.usage("Determine architecture name for current machine.");
|
||||||
|
opts.help(format!("
|
||||||
|
{0} {1}
|
||||||
|
|
||||||
opts.optflag("", "help", "display this help and exit");
|
{0}
|
||||||
opts.optflag("", "version", "output version information and exit");
|
|
||||||
|
|
||||||
let matches = match opts.parse(&args[1..]) {
|
{2}
|
||||||
Ok(m) => m,
|
", NAME, VERSION, usage)).parse(args);
|
||||||
Err(f) => crash!(1, "{}\nTry '{} --help' for more information.", f, NAME),
|
|
||||||
};
|
|
||||||
|
|
||||||
if matches.opt_present("help") {
|
|
||||||
println!("{} {}", NAME, VERSION);
|
|
||||||
println!("");
|
|
||||||
println!("Usage:");
|
|
||||||
println!(" {} [OPTIONS]...", NAME);
|
|
||||||
println!("");
|
|
||||||
print!("{}", opts.usage("Print machine architecture name."));
|
|
||||||
return 0;
|
|
||||||
} else if matches.opt_present("version") {
|
|
||||||
println!("{} {}", NAME, VERSION);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let machine_arch = unsafe { get_machine_arch() };
|
let machine_arch = unsafe { get_machine_arch() };
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue