1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

refactor ~ standardize on 'Try {} --help...' messaging (common markdown-type formatting)

This commit is contained in:
Roy Ivy III 2021-06-30 22:44:43 -05:00 committed by Michael Debertol
parent c5792c2a0f
commit 894d9a068c
16 changed files with 38 additions and 29 deletions

View file

@ -46,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if !matches.is_present(options::NAME) {
crash!(
1,
"{1}\nTry '{0} --help' for more information.",
"{1}\nTry `{0} --help` for more information.",
executable!(),
"missing operand"
);
@ -60,7 +60,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if !multiple_paths && matches.occurrences_of(options::NAME) > 2 {
crash!(
1,
"extra operand '{1}'\nTry '{0} --help' for more information.",
"extra operand '{1}'\nTry `{0} --help` for more information.",
executable!(),
matches.values_of(options::NAME).unwrap().nth(2).unwrap()
);

View file

@ -46,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
Some(v) => Path::new(v),
None => crash!(
1,
"Missing operand: NEWROOT\nTry '{} --help' for more information.",
"Missing operand: NEWROOT\nTry `{} --help` for more information.",
NAME
),
};

View file

@ -99,7 +99,7 @@ quick_error! {
NotImplemented(opt: String) { display("Option '{}' not yet implemented.", opt) }
/// 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!()) }
}
}

View file

@ -70,7 +70,6 @@ mod options {
pub const FILE: &str = "FILE";
}
const NAME: &str = "du";
const SUMMARY: &str = "estimate file space usage";
const LONG_HELP: &str = "
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 {
all: bool,
program_name: String,
util_name: String,
max_depth: Option<usize>,
total: bool,
separate_dirs: bool,
@ -295,7 +294,7 @@ fn du(
safe_writeln!(
stderr(),
"{}: cannot read directory '{}': {}",
options.program_name,
options.util_name,
my_stat.path.display(),
e
);
@ -423,8 +422,9 @@ Valid arguments are:
- 'full-iso'
- 'long-iso'
- 'iso'
Try '{} --help' for more information.",
s, NAME
Try `{} --help` for more information.",
s,
executable!()
),
DuError::InvalidTimeArg(s) => write!(
f,
@ -466,7 +466,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let options = Options {
all: matches.is_present(options::ALL),
program_name: NAME.to_owned(),
util_name: util_name!().to_string(),
max_depth,
total: matches.is_present(options::TOTAL),
separate_dirs: matches.is_present(options::SEPARATE_DIRS),

View file

@ -68,7 +68,7 @@ impl Display for LnError {
}
Self::ExtraOperand(s) => write!(
f,
"extra operand '{}'\nTry '{} --help' for more information.",
"extra operand '{}'\nTry `{} --help` for more information.",
s,
executable!()
),

View file

@ -113,7 +113,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if ch == 'p' {
if matches.is_present("major") || matches.is_present("minor") {
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
} else {
_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")) {
(None, None) | (_, None) | (None, _) => {
eprintln!("Special files require major and minor device numbers.");
eprintln!("Try '{} --help' for more information.", NAME);
eprintln!("Try `{} --help` for more information.", NAME);
1
}
(Some(major), Some(minor)) => {

View file

@ -294,7 +294,7 @@ fn exec(files: &[PathBuf], b: Behavior) -> i32 {
if b.no_target_dir {
show_error!(
"mv: extra operand '{}'\n\
Try '{} --help' for more information.",
Try `{} --help` for more information.",
files[2].display(),
executable!()
);

View file

@ -53,7 +53,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
Some(nstr) => {
if !matches.is_present(options::COMMAND) {
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!()
);
return 125;

View file

@ -69,7 +69,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
// take necessary actions
let paths = matches.values_of(options::PATH);
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
} else {
true

View file

@ -284,7 +284,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let location = &args[0];
if args.len() <= 1 {
println!(
"{0}: missing operand\nTry '{0} --help' for more information.",
"{0}: missing operand\nTry `{0} --help` for more information.",
location
);
return 1;

View file

@ -59,7 +59,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if files.is_empty() {
crash!(
1,
"missing operand\nTry {} --help for more information",
"missing operand\nTry `{} --help` for more information",
NAME
);
}

View file

@ -70,13 +70,13 @@ impl FromStr for Number {
Ok(n) => Ok(Number::BigInt(n)),
Err(_) => match s.parse::<f64>() {
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,
executable!(),
)),
Ok(value) => Ok(Number::F64(value)),
Err(_) => Err(format!(
"invalid floating point argument: '{}'\nTry '{} --help' for more information.",
"invalid floating point argument: '{}'\nTry `{} --help` for more information.",
s,
executable!(),
)),
@ -121,7 +121,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
};
if increment.is_zero() {
show_error!(
"invalid Zero increment value: '{}'\nTry '{} --help' for more information.",
"invalid Zero increment value: '{}'\nTry `{} --help` for more information.",
numbers[1],
executable!()
);

View file

@ -156,8 +156,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
let options = ProgramOptions::try_from(&matches)
.unwrap_or_else(|e| crash!(125, "{}\nTry 'stdbuf --help' for more information.", e.0));
let options = ProgramOptions::try_from(&matches).unwrap_or_else(|e| {
crash!(
125,
"{}\nTry `{} --help` for more information.",
e.0,
executable!()
)
});
let mut command_values = matches.values_of::<&str>(options::COMMAND).unwrap();
let mut command = Command::new(command_values.next().unwrap());

View file

@ -43,13 +43,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if paths.is_empty() {
crash!(
1,
"missing operand\nTry '{0} --help' for more information.",
"missing operand\nTry `{0} --help` for more information.",
executable!()
);
} else if paths.len() > 1 {
crash!(
1,
"extra operand: '{1}'\nTry '{0} --help' for more information.",
"extra operand: '{1}'\nTry `{0} --help` for more information.",
executable!(),
paths[1]
);

View file

@ -203,8 +203,8 @@ pub trait UError: Error + Send {
/// Print usage help to a custom error.
///
/// 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}
/// --help' for more information." and printed only if `true` is returned.
/// below the error message. The usage help is in the format: "Try `{name}
/// --help` for more information." and printed only if `true` is returned.
///
/// # Example
///
@ -519,7 +519,7 @@ macro_rules! uio_error(
/// let res: UResult<()> = Err(1.into());
/// ```
/// This type is especially useful for a trivial conversion from utils returning [`i32`] to
/// returning [`UResult`].
/// returning [`UResult`].
#[derive(Debug)]
pub struct ExitCode(pub i32);

View file

@ -104,7 +104,7 @@ pub fn gen_uumain(_args: TokenStream, stream: TokenStream) -> TokenStream {
show_error!("{}", s);
}
if e.usage() {
eprintln!("Try '{} --help' for more information.", executable!());
eprintln!("Try `{} --help` for more information.", executable!());
}
e.code()
}