mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-05 07:27:46 +00:00
coreopts: display package name instead of module path
This commit is contained in:
parent
bcec54f572
commit
789141d926
2 changed files with 18 additions and 14 deletions
|
@ -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,18 +38,20 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,7 @@ macro_rules! snippet_list_join_or {
|
||||||
);
|
);
|
||||||
($valOne:expr, $valTwo:expr $(, $remainingVals:expr)*) => (
|
($valOne:expr, $valTwo:expr $(, $remainingVals:expr)*) => (
|
||||||
format!("{}, {}", $valOne, snippet_list_join_oxford!("or", $valTwo $(, $remainingVals)*))
|
format!("{}, {}", $valOne, snippet_list_join_oxford!("or", $valTwo $(, $remainingVals)*))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- message templates : help and version
|
//-- message templates : help and version
|
||||||
|
@ -294,7 +294,7 @@ macro_rules! msg_invalid_opt_use {
|
||||||
msg_invalid_input!(format!("The '{}' ('{}') option {}", $longflag, $shortflag, $about))
|
msg_invalid_input!(format!("The '{}' ('{}') option {}", $longflag, $shortflag, $about))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! msg_opt_only_usable_if {
|
macro_rules! msg_opt_only_usable_if {
|
||||||
($clause:expr, $flag:expr) => (
|
($clause:expr, $flag:expr) => (
|
||||||
|
@ -327,24 +327,24 @@ macro_rules! msg_args_invalid_value { ($expects:expr, $received:expr) => (
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! msg_args_nonexistent_file { ($received:expr) => (
|
macro_rules! msg_args_nonexistent_file { ($received:expr) => (
|
||||||
msg_args_invalid_value!("paths to files", snippet_no_file_at_path!($received)));}
|
msg_args_invalid_value!("paths to files", snippet_no_file_at_path!($received)));}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! msg_wrong_number_of_arguments { ($received:expr) => (
|
macro_rules! msg_wrong_number_of_arguments { ($received:expr) => (
|
||||||
msg_args_invalid_value!("wrong number of arguments") ); }
|
msg_args_invalid_value!("wrong number of arguments") ); }
|
||||||
|
|
||||||
// -- message templates : invalid input : input combinations
|
// -- message templates : invalid input : input combinations
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! msg_expects_one_of {
|
macro_rules! msg_expects_one_of {
|
||||||
($valOne:expr $(, $remainingVals:expr)*) => (
|
($valOne:expr $(, $remainingVals:expr)*) => (
|
||||||
msg_invalid_input!(format!("expects one of {}", snippet_list_join_or!($valOne $(, $remainingVals)*)))
|
msg_invalid_input!(format!("expects one of {}", snippet_list_join_or!($valOne $(, $remainingVals)*)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! msg_expects_no_more_than_one_of {
|
macro_rules! msg_expects_no_more_than_one_of {
|
||||||
($valOne:expr $(, $remainingVals:expr)*) => (
|
($valOne:expr $(, $remainingVals:expr)*) => (
|
||||||
msg_invalid_input!(format!("expects no more than one of {}", snippet_list_join_or!($valOne $(, $remainingVals)*))) ;
|
msg_invalid_input!(format!("expects no more than one of {}", snippet_list_join_or!($valOne $(, $remainingVals)*))) ;
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue