From 1bf2c82520b6e675432da664aaa22feb6e7bdc64 Mon Sep 17 00:00:00 2001 From: Nathan Ross Date: Mon, 8 Aug 2016 04:04:24 -0400 Subject: [PATCH] arch: use message templates for consistent, original-work error handling --- src/arch/Cargo.toml | 1 - src/arch/arch.rs | 29 +++++++---------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/arch/Cargo.toml b/src/arch/Cargo.toml index 251ca48a0..ef886adc0 100644 --- a/src/arch/Cargo.toml +++ b/src/arch/Cargo.toml @@ -8,7 +8,6 @@ name = "uu_arch" path = "arch.rs" [dependencies] -getopts = "*" libc = "*" uucore = { path="../uucore" } diff --git a/src/arch/arch.rs b/src/arch/arch.rs index 4b018d1b3..05d9bd63b 100644 --- a/src/arch/arch.rs +++ b/src/arch/arch.rs @@ -9,14 +9,12 @@ * file that was distributed with this source code. */ -extern crate getopts; extern crate libc; #[macro_use] extern crate uucore; use std::ffi::CStr; -use std::io::Write; use std::mem::uninitialized; use uucore::c_types::utsname; @@ -44,28 +42,15 @@ static NAME: &'static str = "arch"; static VERSION: &'static str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> 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"); - opts.optflag("", "version", "output version information and exit"); +{0} - let matches = match opts.parse(&args[1..]) { - Ok(m) => m, - 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; - } +{2} +", NAME, VERSION, usage)).parse(args); let machine_arch = unsafe { get_machine_arch() }; let mut output = String::new();