mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
refactor ~ standardize on 'Try {} --help
...' messaging (common markdown-type formatting)
This commit is contained in:
parent
c5792c2a0f
commit
894d9a068c
16 changed files with 38 additions and 29 deletions
|
@ -46,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
if !matches.is_present(options::NAME) {
|
if !matches.is_present(options::NAME) {
|
||||||
crash!(
|
crash!(
|
||||||
1,
|
1,
|
||||||
"{1}\nTry '{0} --help' for more information.",
|
"{1}\nTry `{0} --help` for more information.",
|
||||||
executable!(),
|
executable!(),
|
||||||
"missing operand"
|
"missing operand"
|
||||||
);
|
);
|
||||||
|
@ -60,7 +60,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
if !multiple_paths && matches.occurrences_of(options::NAME) > 2 {
|
if !multiple_paths && matches.occurrences_of(options::NAME) > 2 {
|
||||||
crash!(
|
crash!(
|
||||||
1,
|
1,
|
||||||
"extra operand '{1}'\nTry '{0} --help' for more information.",
|
"extra operand '{1}'\nTry `{0} --help` for more information.",
|
||||||
executable!(),
|
executable!(),
|
||||||
matches.values_of(options::NAME).unwrap().nth(2).unwrap()
|
matches.values_of(options::NAME).unwrap().nth(2).unwrap()
|
||||||
);
|
);
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
Some(v) => Path::new(v),
|
Some(v) => Path::new(v),
|
||||||
None => crash!(
|
None => crash!(
|
||||||
1,
|
1,
|
||||||
"Missing operand: NEWROOT\nTry '{} --help' for more information.",
|
"Missing operand: NEWROOT\nTry `{} --help` for more information.",
|
||||||
NAME
|
NAME
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
|
@ -99,7 +99,7 @@ quick_error! {
|
||||||
NotImplemented(opt: String) { display("Option '{}' not yet implemented.", opt) }
|
NotImplemented(opt: String) { display("Option '{}' not yet implemented.", opt) }
|
||||||
|
|
||||||
/// Invalid arguments to backup
|
/// Invalid arguments to backup
|
||||||
Backup(description: String) { display("{}\nTry 'cp --help' for more information.", description) }
|
Backup(description: String) { display("{}\nTry `{} --help` for more information.", description, executable!()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,6 @@ mod options {
|
||||||
pub const FILE: &str = "FILE";
|
pub const FILE: &str = "FILE";
|
||||||
}
|
}
|
||||||
|
|
||||||
const NAME: &str = "du";
|
|
||||||
const SUMMARY: &str = "estimate file space usage";
|
const SUMMARY: &str = "estimate file space usage";
|
||||||
const LONG_HELP: &str = "
|
const LONG_HELP: &str = "
|
||||||
Display values are in units of the first available SIZE from --block-size,
|
Display values are in units of the first available SIZE from --block-size,
|
||||||
|
@ -87,7 +86,7 @@ const UNITS: [(char, u32); 6] = [('E', 6), ('P', 5), ('T', 4), ('G', 3), ('M', 2
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
all: bool,
|
all: bool,
|
||||||
program_name: String,
|
util_name: String,
|
||||||
max_depth: Option<usize>,
|
max_depth: Option<usize>,
|
||||||
total: bool,
|
total: bool,
|
||||||
separate_dirs: bool,
|
separate_dirs: bool,
|
||||||
|
@ -295,7 +294,7 @@ fn du(
|
||||||
safe_writeln!(
|
safe_writeln!(
|
||||||
stderr(),
|
stderr(),
|
||||||
"{}: cannot read directory '{}': {}",
|
"{}: cannot read directory '{}': {}",
|
||||||
options.program_name,
|
options.util_name,
|
||||||
my_stat.path.display(),
|
my_stat.path.display(),
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
@ -423,8 +422,9 @@ Valid arguments are:
|
||||||
- 'full-iso'
|
- 'full-iso'
|
||||||
- 'long-iso'
|
- 'long-iso'
|
||||||
- 'iso'
|
- 'iso'
|
||||||
Try '{} --help' for more information.",
|
Try `{} --help` for more information.",
|
||||||
s, NAME
|
s,
|
||||||
|
executable!()
|
||||||
),
|
),
|
||||||
DuError::InvalidTimeArg(s) => write!(
|
DuError::InvalidTimeArg(s) => write!(
|
||||||
f,
|
f,
|
||||||
|
@ -466,7 +466,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
let options = Options {
|
let options = Options {
|
||||||
all: matches.is_present(options::ALL),
|
all: matches.is_present(options::ALL),
|
||||||
program_name: NAME.to_owned(),
|
util_name: util_name!().to_string(),
|
||||||
max_depth,
|
max_depth,
|
||||||
total: matches.is_present(options::TOTAL),
|
total: matches.is_present(options::TOTAL),
|
||||||
separate_dirs: matches.is_present(options::SEPARATE_DIRS),
|
separate_dirs: matches.is_present(options::SEPARATE_DIRS),
|
||||||
|
|
|
@ -68,7 +68,7 @@ impl Display for LnError {
|
||||||
}
|
}
|
||||||
Self::ExtraOperand(s) => write!(
|
Self::ExtraOperand(s) => write!(
|
||||||
f,
|
f,
|
||||||
"extra operand '{}'\nTry '{} --help' for more information.",
|
"extra operand '{}'\nTry `{} --help` for more information.",
|
||||||
s,
|
s,
|
||||||
executable!()
|
executable!()
|
||||||
),
|
),
|
||||||
|
|
|
@ -113,7 +113,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
if ch == 'p' {
|
if ch == 'p' {
|
||||||
if matches.is_present("major") || matches.is_present("minor") {
|
if matches.is_present("major") || matches.is_present("minor") {
|
||||||
eprintln!("Fifos do not have major and minor device numbers.");
|
eprintln!("Fifos do not have major and minor device numbers.");
|
||||||
eprintln!("Try '{} --help' for more information.", NAME);
|
eprintln!("Try `{} --help` for more information.", NAME);
|
||||||
1
|
1
|
||||||
} else {
|
} else {
|
||||||
_mknod(file_name, S_IFIFO | mode, 0)
|
_mknod(file_name, S_IFIFO | mode, 0)
|
||||||
|
@ -122,7 +122,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
match (matches.value_of("major"), matches.value_of("minor")) {
|
match (matches.value_of("major"), matches.value_of("minor")) {
|
||||||
(None, None) | (_, None) | (None, _) => {
|
(None, None) | (_, None) | (None, _) => {
|
||||||
eprintln!("Special files require major and minor device numbers.");
|
eprintln!("Special files require major and minor device numbers.");
|
||||||
eprintln!("Try '{} --help' for more information.", NAME);
|
eprintln!("Try `{} --help` for more information.", NAME);
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
(Some(major), Some(minor)) => {
|
(Some(major), Some(minor)) => {
|
||||||
|
|
|
@ -294,7 +294,7 @@ fn exec(files: &[PathBuf], b: Behavior) -> i32 {
|
||||||
if b.no_target_dir {
|
if b.no_target_dir {
|
||||||
show_error!(
|
show_error!(
|
||||||
"mv: extra operand '{}'\n\
|
"mv: extra operand '{}'\n\
|
||||||
Try '{} --help' for more information.",
|
Try `{} --help` for more information.",
|
||||||
files[2].display(),
|
files[2].display(),
|
||||||
executable!()
|
executable!()
|
||||||
);
|
);
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
Some(nstr) => {
|
Some(nstr) => {
|
||||||
if !matches.is_present(options::COMMAND) {
|
if !matches.is_present(options::COMMAND) {
|
||||||
show_error!(
|
show_error!(
|
||||||
"A command must be given with an adjustment.\nTry \"{} --help\" for more information.",
|
"A command must be given with an adjustment.\nTry `{} --help` for more information.",
|
||||||
executable!()
|
executable!()
|
||||||
);
|
);
|
||||||
return 125;
|
return 125;
|
||||||
|
|
|
@ -69,7 +69,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
// take necessary actions
|
// take necessary actions
|
||||||
let paths = matches.values_of(options::PATH);
|
let paths = matches.values_of(options::PATH);
|
||||||
let mut res = if paths.is_none() {
|
let mut res = if paths.is_none() {
|
||||||
show_error!("missing operand\nTry {} --help for more information", NAME);
|
show_error!(
|
||||||
|
"missing operand\nTry `{} --help` for more information",
|
||||||
|
NAME
|
||||||
|
);
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
|
|
@ -284,7 +284,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let location = &args[0];
|
let location = &args[0];
|
||||||
if args.len() <= 1 {
|
if args.len() <= 1 {
|
||||||
println!(
|
println!(
|
||||||
"{0}: missing operand\nTry '{0} --help' for more information.",
|
"{0}: missing operand\nTry `{0} --help` for more information.",
|
||||||
location
|
location
|
||||||
);
|
);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
crash!(
|
crash!(
|
||||||
1,
|
1,
|
||||||
"missing operand\nTry {} --help for more information",
|
"missing operand\nTry `{} --help` for more information",
|
||||||
NAME
|
NAME
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,13 +70,13 @@ impl FromStr for Number {
|
||||||
Ok(n) => Ok(Number::BigInt(n)),
|
Ok(n) => Ok(Number::BigInt(n)),
|
||||||
Err(_) => match s.parse::<f64>() {
|
Err(_) => match s.parse::<f64>() {
|
||||||
Ok(value) if value.is_nan() => Err(format!(
|
Ok(value) if value.is_nan() => Err(format!(
|
||||||
"invalid 'not-a-number' argument: '{}'\nTry '{} --help' for more information.",
|
"invalid 'not-a-number' argument: '{}'\nTry `{} --help` for more information.",
|
||||||
s,
|
s,
|
||||||
executable!(),
|
executable!(),
|
||||||
)),
|
)),
|
||||||
Ok(value) => Ok(Number::F64(value)),
|
Ok(value) => Ok(Number::F64(value)),
|
||||||
Err(_) => Err(format!(
|
Err(_) => Err(format!(
|
||||||
"invalid floating point argument: '{}'\nTry '{} --help' for more information.",
|
"invalid floating point argument: '{}'\nTry `{} --help` for more information.",
|
||||||
s,
|
s,
|
||||||
executable!(),
|
executable!(),
|
||||||
)),
|
)),
|
||||||
|
@ -121,7 +121,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
};
|
};
|
||||||
if increment.is_zero() {
|
if increment.is_zero() {
|
||||||
show_error!(
|
show_error!(
|
||||||
"invalid Zero increment value: '{}'\nTry '{} --help' for more information.",
|
"invalid Zero increment value: '{}'\nTry `{} --help` for more information.",
|
||||||
numbers[1],
|
numbers[1],
|
||||||
executable!()
|
executable!()
|
||||||
);
|
);
|
||||||
|
|
|
@ -156,8 +156,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
||||||
|
|
||||||
let options = ProgramOptions::try_from(&matches)
|
let options = ProgramOptions::try_from(&matches).unwrap_or_else(|e| {
|
||||||
.unwrap_or_else(|e| crash!(125, "{}\nTry 'stdbuf --help' for more information.", e.0));
|
crash!(
|
||||||
|
125,
|
||||||
|
"{}\nTry `{} --help` for more information.",
|
||||||
|
e.0,
|
||||||
|
executable!()
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let mut command_values = matches.values_of::<&str>(options::COMMAND).unwrap();
|
let mut command_values = matches.values_of::<&str>(options::COMMAND).unwrap();
|
||||||
let mut command = Command::new(command_values.next().unwrap());
|
let mut command = Command::new(command_values.next().unwrap());
|
||||||
|
|
|
@ -43,13 +43,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
crash!(
|
crash!(
|
||||||
1,
|
1,
|
||||||
"missing operand\nTry '{0} --help' for more information.",
|
"missing operand\nTry `{0} --help` for more information.",
|
||||||
executable!()
|
executable!()
|
||||||
);
|
);
|
||||||
} else if paths.len() > 1 {
|
} else if paths.len() > 1 {
|
||||||
crash!(
|
crash!(
|
||||||
1,
|
1,
|
||||||
"extra operand: '{1}'\nTry '{0} --help' for more information.",
|
"extra operand: '{1}'\nTry `{0} --help` for more information.",
|
||||||
executable!(),
|
executable!(),
|
||||||
paths[1]
|
paths[1]
|
||||||
);
|
);
|
||||||
|
|
|
@ -203,8 +203,8 @@ pub trait UError: Error + Send {
|
||||||
/// Print usage help to a custom error.
|
/// Print usage help to a custom error.
|
||||||
///
|
///
|
||||||
/// Return true or false to control whether a short usage help is printed
|
/// Return true or false to control whether a short usage help is printed
|
||||||
/// below the error message. The usage help is in the format: "Try '{name}
|
/// below the error message. The usage help is in the format: "Try `{name}
|
||||||
/// --help' for more information." and printed only if `true` is returned.
|
/// --help` for more information." and printed only if `true` is returned.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -519,7 +519,7 @@ macro_rules! uio_error(
|
||||||
/// let res: UResult<()> = Err(1.into());
|
/// let res: UResult<()> = Err(1.into());
|
||||||
/// ```
|
/// ```
|
||||||
/// This type is especially useful for a trivial conversion from utils returning [`i32`] to
|
/// This type is especially useful for a trivial conversion from utils returning [`i32`] to
|
||||||
/// returning [`UResult`].
|
/// returning [`UResult`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ExitCode(pub i32);
|
pub struct ExitCode(pub i32);
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ pub fn gen_uumain(_args: TokenStream, stream: TokenStream) -> TokenStream {
|
||||||
show_error!("{}", s);
|
show_error!("{}", s);
|
||||||
}
|
}
|
||||||
if e.usage() {
|
if e.usage() {
|
||||||
eprintln!("Try '{} --help' for more information.", executable!());
|
eprintln!("Try `{} --help` for more information.", executable!());
|
||||||
}
|
}
|
||||||
e.code()
|
e.code()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue