From 894d9a068cf83b456e596e35f4316b23ebda2ff2 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 22:44:43 -0500 Subject: [PATCH] refactor ~ standardize on 'Try `{} --help`...' messaging (common markdown-type formatting) --- src/uu/basename/src/basename.rs | 4 ++-- src/uu/chroot/src/chroot.rs | 2 +- src/uu/cp/src/cp.rs | 2 +- src/uu/du/src/du.rs | 12 ++++++------ src/uu/ln/src/ln.rs | 2 +- src/uu/mknod/src/mknod.rs | 4 ++-- src/uu/mv/src/mv.rs | 2 +- src/uu/nice/src/nice.rs | 2 +- src/uu/pathchk/src/pathchk.rs | 5 ++++- src/uu/printf/src/printf.rs | 2 +- src/uu/readlink/src/readlink.rs | 2 +- src/uu/seq/src/seq.rs | 6 +++--- src/uu/stdbuf/src/stdbuf.rs | 10 ++++++++-- src/uu/unlink/src/unlink.rs | 4 ++-- src/uucore/src/lib/mods/error.rs | 6 +++--- src/uucore_procs/src/lib.rs | 2 +- 16 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index 26fb67c54..aa1e2fa2d 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -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() ); diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index b548b7734..01a7c6b84 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -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 ), }; diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 8920cd439..542e9bfee 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -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!()) } } } diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 02a05b911..6160f5490 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -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, 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), diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index a9a8379a0..568c97e45 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -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!() ), diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 72b35cd33..bd26949cd 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -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)) => { diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 5f7431203..c064a2244 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -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!() ); diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index 62565fc5c..3b62d8058 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -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; diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 44e4ed4ac..46edf0850 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -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 diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index bc672156f..211522fbf 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -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; diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index 7ae2f9423..4bfac4630 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -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 ); } diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 589e8450d..ae81aa71d 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -70,13 +70,13 @@ impl FromStr for Number { Ok(n) => Ok(Number::BigInt(n)), Err(_) => match s.parse::() { 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!() ); diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 469fffbdc..60f42102d 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -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()); diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index 7c0e596fb..5f96cf429 100644 --- a/src/uu/unlink/src/unlink.rs +++ b/src/uu/unlink/src/unlink.rs @@ -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] ); diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index 664fc9841..c2b3069c8 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -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); diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index f62e4178e..2467ce2c7 100644 --- a/src/uucore_procs/src/lib.rs +++ b/src/uucore_procs/src/lib.rs @@ -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() }