1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #957 from knight42/fix-message-template

coreopts: display package name instead of module path
This commit is contained in:
mpkh 2016-08-09 20:59:39 +04:00 committed by GitHub
commit ab345f133a
4 changed files with 42 additions and 38 deletions

View file

@ -42,7 +42,7 @@ 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 = uucore::coreopts::CoreOptions::new(); let mut opts = uucore::coreopts::CoreOptions::new(NAME);
let usage = opts.usage("Determine architecture name for current machine."); let usage = opts.usage("Determine architecture name for current machine.");
opts.help(format!(" opts.help(format!("
{0} {1} {0} {1}

View file

@ -408,7 +408,7 @@ fn cut_files(mut filenames: Vec<String>, mode: Mode) -> i32 {
} }
pub fn uumain(args: Vec<String>) -> i32 { pub fn uumain(args: Vec<String>) -> i32 {
let mut opts = uucore::coreopts::CoreOptions::new(); let mut opts = uucore::coreopts::CoreOptions::new(NAME);
opts.optopt("b", "bytes", "filter byte columns from the input source", "sequence"); opts.optopt("b", "bytes", "filter byte columns from the input source", "sequence");
opts.optopt("c", "characters", "alias for character mode", "sequence"); opts.optopt("c", "characters", "alias for character mode", "sequence");

View file

@ -3,14 +3,16 @@ use std::io::Write;
pub struct CoreOptions { pub struct CoreOptions {
pub options : getopts::Options, pub options : getopts::Options,
pkgname: &'static str,
longhelp : Option<String> longhelp : Option<String>
} }
impl<'a> CoreOptions { impl<'a> CoreOptions {
pub fn new() -> Self { pub fn new(name: &'static str) -> Self {
let mut ret = CoreOptions { let mut ret = CoreOptions {
options : getopts::Options::new(), options : getopts::Options::new(),
longhelp : None pkgname: name,
longhelp: None
}; };
ret.options ret.options
.optflag("", "help", "print usage information") .optflag("", "help", "print usage information")
@ -36,16 +38,18 @@ impl<'a> CoreOptions {
let matches = match self.options.parse(&args[1..]) { let matches = match self.options.parse(&args[1..]) {
Ok(m) => { Some(m) }, Ok(m) => { Some(m) },
Err(f) => { Err(f) => {
crash!(1, "{}", msg_invalid_input!(format!("{}", f))); eprintln!("{}: {}", self.pkgname, f);
eprintln!("Try '{} --help' for more information.", self.pkgname);
exit!(1)
} }
}.unwrap(); }.unwrap();
if matches.opt_present("help") { if matches.opt_present("help") {
exit!(match self.longhelp { exit!(match self.longhelp {
Some(ref lhelp) => { print!("{}", lhelp); 0} Some(ref lhelp) => { println!("{}", lhelp); 0}
None => 1 None => 1
}); });
} else if matches.opt_present("version") { } else if matches.opt_present("version") {
print!("{}", msg_version!()); println!("{} {}", self.pkgname, env!("CARGO_PKG_VERSION"));
exit!(0); exit!(0);
} }
matches matches