From 6f58da00dd43da607a13502206f5bbd0961634f5 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Wed, 30 Jun 2021 23:27:10 +0200 Subject: [PATCH 01/25] refactor/uucore ~ add `util_name!()`; correct implementation of `executable!()` --- src/uucore/src/lib/macros.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 6e3a2166f..3eeb4d625 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -5,19 +5,24 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -/// Deduce the name of the binary from the current source code filename. -/// -/// e.g.: `src/uu/cp/src/cp.rs` -> `cp` +/// Get the utility name. +#[macro_export] +macro_rules! util_name( + () => ({ + let crate_name = env!("CARGO_PKG_NAME"); + if crate_name.starts_with("uu_") { + &crate_name[3..] + } else { + &crate_name + } + }) +); + +/// Get the executable name. #[macro_export] macro_rules! executable( () => ({ - let module = module_path!(); - let module = module.split("::").next().unwrap_or(module); - if &module[0..3] == "uu_" { - &module[3..] - } else { - module - } + &std::env::args().next().unwrap() }) ); From be8f0732175fb81af362c4d1b24b1f8a7f55015b Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 21:59:04 -0500 Subject: [PATCH 02/25] refactor/uucore ~ add OsString support for `executable!()` --- src/uucore/src/lib/macros.rs | 41 ++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 3eeb4d625..e659c4757 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -18,11 +18,33 @@ macro_rules! util_name( }) ); -/// Get the executable name. +/// Get the executable path (as `OsString`). +#[macro_export] +macro_rules! executable_os( + () => ({ + &std::env::args_os().next().unwrap() + }) +); + +/// Get the executable path (as `String`; lossless). #[macro_export] macro_rules! executable( () => ({ - &std::env::args().next().unwrap() + let exe = match executable_os!().to_str() { + // * UTF-8 + Some(s) => s.to_string(), + // * "lossless" debug format if `executable_os!()` is not well-formed UTF-8 + None => format!("{:?}", executable_os!()) + }; + &exe.to_owned() + }) +); + +/// Get the executable name. +#[macro_export] +macro_rules! executable_name( + () => ({ + &std::path::Path::new(executable_os!()).file_stem().unwrap().to_string_lossy() }) ); @@ -31,10 +53,7 @@ macro_rules! show( ($err:expr) => ({ let e = $err; uucore::error::set_exit_code(e.code()); - eprintln!("{}: {}", executable!(), e); - if e.usage() { - eprintln!("Try '{} --help' for more information.", executable!()); - } + eprintln!("{}: {}", executable_name!(), e); }) ); @@ -51,7 +70,7 @@ macro_rules! show_if_err( #[macro_export] macro_rules! show_error( ($($args:tt)+) => ({ - eprint!("{}: ", executable!()); + eprint!("{}: ", executable_name!()); eprintln!($($args)+); }) ); @@ -60,7 +79,7 @@ macro_rules! show_error( #[macro_export] macro_rules! show_error_custom_description ( ($err:expr,$($args:tt)+) => ({ - eprint!("{}: {}: ", executable!(), $err); + eprint!("{}: {}: ", executable_name!(), $err); eprintln!($($args)+); }) ); @@ -68,7 +87,7 @@ macro_rules! show_error_custom_description ( #[macro_export] macro_rules! show_warning( ($($args:tt)+) => ({ - eprint!("{}: warning: ", executable!()); + eprint!("{}: warning: ", executable_name!()); eprintln!($($args)+); }) ); @@ -77,9 +96,9 @@ macro_rules! show_warning( #[macro_export] macro_rules! show_usage_error( ($($args:tt)+) => ({ - eprint!("{}: ", executable!()); + eprint!("{}: ", executable_name!()); eprintln!($($args)+); - eprintln!("Try '{} --help' for more information.", executable!()); + eprintln!("Try `{:?} --help` for more information.", executable!()); }) ); From 27c4530f3c67d53718a884e32b9c33b8bbb1d8ef Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 22:14:37 -0500 Subject: [PATCH 03/25] refactor/uucore ~ reorganize macros into sections by 'type' --- src/uucore/src/lib/macros.rs | 50 +++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index e659c4757..5a374b36e 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -5,19 +5,6 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -/// Get the utility name. -#[macro_export] -macro_rules! util_name( - () => ({ - let crate_name = env!("CARGO_PKG_NAME"); - if crate_name.starts_with("uu_") { - &crate_name[3..] - } else { - &crate_name - } - }) -); - /// Get the executable path (as `OsString`). #[macro_export] macro_rules! executable_os( @@ -48,6 +35,21 @@ macro_rules! executable_name( }) ); +/// Derive the utility name. +#[macro_export] +macro_rules! util_name( + () => ({ + let crate_name = env!("CARGO_PKG_NAME"); + if crate_name.starts_with("uu_") { + &crate_name[3..] + } else { + &crate_name + } + }) +); + +//==== + #[macro_export] macro_rules! show( ($err:expr) => ({ @@ -102,14 +104,7 @@ macro_rules! show_usage_error( }) ); -/// Display the provided error message, then `exit()` with the provided exit code -#[macro_export] -macro_rules! crash( - ($exit_code:expr, $($args:tt)+) => ({ - show_error!($($args)+); - ::std::process::exit($exit_code) - }) -); +//==== /// Calls `exit()` with the provided exit code. #[macro_export] @@ -119,6 +114,15 @@ macro_rules! exit( }) ); +/// Display the provided error message, then `exit()` with the provided exit code +#[macro_export] +macro_rules! crash( + ($exit_code:expr, $($args:tt)+) => ({ + show_error!($($args)+); + ::std::process::exit($exit_code) + }) +); + /// Unwraps the Result. Instead of panicking, it exists the program with the /// provided exit code. #[macro_export] @@ -131,6 +135,8 @@ macro_rules! crash_if_err( ) ); +//==== + /// Unwraps the Result. Instead of panicking, it shows the error and then /// returns from the function with the provided exit code. /// Assumes the current function returns an i32 value. @@ -147,6 +153,8 @@ macro_rules! return_if_err( ) ); +//==== + #[macro_export] macro_rules! safe_write( ($fd:expr, $($args:tt)+) => ( From 065330c4ca066c593f83909f5e0c7d6528230f65 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 22:18:13 -0500 Subject: [PATCH 04/25] refactor/uucore ~ improve `crash!()` (DRY use of `exit!()`) --- src/uucore/src/lib/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 5a374b36e..090fbd00c 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -119,7 +119,7 @@ macro_rules! exit( macro_rules! crash( ($exit_code:expr, $($args:tt)+) => ({ show_error!($($args)+); - ::std::process::exit($exit_code) + exit!($exit_code) }) ); From ed240a7e50d4209019944ef8b0aab1317e6337ad Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 22:19:18 -0500 Subject: [PATCH 05/25] fix/uucore ~ revise and fix msg macros and sub-macros --- src/uucore/src/lib/macros.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 090fbd00c..63d105b1b 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -189,25 +189,25 @@ macro_rules! safe_unwrap( //-- message templates -//-- message templates : general +//-- message templates : (join utility sub-macros) #[macro_export] -macro_rules! snippet_list_join_oxford { +macro_rules! snippet_list_join_oxford_comma { ($conjunction:expr, $valOne:expr, $valTwo:expr) => ( format!("{}, {} {}", $valOne, $conjunction, $valTwo) ); ($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => ( - format!("{}, {}", $valOne, snippet_list_join_inner!($conjunction, $valTwo $(, $remaining_values)*)) + format!("{}, {}", $valOne, snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*)) ); } #[macro_export] -macro_rules! snippet_list_join_or { - ($valOne:expr, $valTwo:expr) => ( - format!("{} or {}", $valOne, $valTwo) +macro_rules! snippet_list_join { + ($conjunction:expr, $valOne:expr, $valTwo:expr) => ( + format!("{} {} {}", $valOne, $conjunction, $valTwo) ); - ($valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => ( - format!("{}, {}", $valOne, snippet_list_join_oxford!("or", $valTwo $(, $remaining_values)*)) + ($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => ( + format!("{}, {}", $valOne, snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*)) ); } @@ -271,13 +271,13 @@ macro_rules! msg_opt_invalid_should_be { #[macro_export] macro_rules! msg_expects_one_of { ($valOne:expr $(, $remaining_values:expr)*) => ( - msg_invalid_input!(format!("expects one of {}", snippet_list_join_or!($valOne $(, $remaining_values)*))) + msg_invalid_input!(format!("expects one of {}", snippet_list_join!("or", $valOne $(, $remaining_values)*))) ); } #[macro_export] macro_rules! msg_expects_no_more_than_one_of { ($valOne:expr $(, $remaining_values:expr)*) => ( - msg_invalid_input!(format!("expects no more than one of {}", snippet_list_join_or!($valOne $(, $remaining_values)*))) ; + msg_invalid_input!(format!("expects no more than one of {}", snippet_list_join!("or", $valOne $(, $remaining_values)*))) ; ); } From fa5dc90789bba6c80ecf03546f9f733ccc7d021f Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 22:24:41 -0500 Subject: [PATCH 06/25] refactor/uucore ~ improve macro scope hygiene --- src/uucore/src/lib/macros.rs | 48 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 63d105b1b..715752c84 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -17,11 +17,11 @@ macro_rules! executable_os( #[macro_export] macro_rules! executable( () => ({ - let exe = match executable_os!().to_str() { + let exe = match $crate::executable_os!().to_str() { // * UTF-8 Some(s) => s.to_string(), // * "lossless" debug format if `executable_os!()` is not well-formed UTF-8 - None => format!("{:?}", executable_os!()) + None => format!("{:?}", $crate::executable_os!()) }; &exe.to_owned() }) @@ -31,7 +31,7 @@ macro_rules! executable( #[macro_export] macro_rules! executable_name( () => ({ - &std::path::Path::new(executable_os!()).file_stem().unwrap().to_string_lossy() + &std::path::Path::new($crate::executable_os!()).file_stem().unwrap().to_string_lossy() }) ); @@ -55,7 +55,7 @@ macro_rules! show( ($err:expr) => ({ let e = $err; uucore::error::set_exit_code(e.code()); - eprintln!("{}: {}", executable_name!(), e); + eprintln!("{}: {}", $crate::executable_name!(), e); }) ); @@ -72,7 +72,7 @@ macro_rules! show_if_err( #[macro_export] macro_rules! show_error( ($($args:tt)+) => ({ - eprint!("{}: ", executable_name!()); + eprint!("{}: ", $crate::executable_name!()); eprintln!($($args)+); }) ); @@ -81,7 +81,7 @@ macro_rules! show_error( #[macro_export] macro_rules! show_error_custom_description ( ($err:expr,$($args:tt)+) => ({ - eprint!("{}: {}: ", executable_name!(), $err); + eprint!("{}: {}: ", $crate::executable_name!(), $err); eprintln!($($args)+); }) ); @@ -89,7 +89,7 @@ macro_rules! show_error_custom_description ( #[macro_export] macro_rules! show_warning( ($($args:tt)+) => ({ - eprint!("{}: warning: ", executable_name!()); + eprint!("{}: warning: ", $crate::executable_name!()); eprintln!($($args)+); }) ); @@ -98,9 +98,9 @@ macro_rules! show_warning( #[macro_export] macro_rules! show_usage_error( ($($args:tt)+) => ({ - eprint!("{}: ", executable_name!()); + eprint!("{}: ", $crate::executable_name!()); eprintln!($($args)+); - eprintln!("Try `{:?} --help` for more information.", executable!()); + eprintln!("Try `{:?} --help` for more information.", $crate::executable!()); }) ); @@ -118,8 +118,8 @@ macro_rules! exit( #[macro_export] macro_rules! crash( ($exit_code:expr, $($args:tt)+) => ({ - show_error!($($args)+); - exit!($exit_code) + $crate::show_error!($($args)+); + $crate::exit!($exit_code) }) ); @@ -130,7 +130,7 @@ macro_rules! crash_if_err( ($exit_code:expr, $exp:expr) => ( match $exp { Ok(m) => m, - Err(f) => crash!($exit_code, "{}", f), + Err(f) => $crate::crash!($exit_code, "{}", f), } ) ); @@ -146,7 +146,7 @@ macro_rules! return_if_err( match $exp { Ok(m) => m, Err(f) => { - show_error!("{}", f); + $crate::show_error!("{}", f); return $exit_code; } } @@ -182,7 +182,7 @@ macro_rules! safe_unwrap( ($exp:expr) => ( match $exp { Ok(m) => m, - Err(f) => crash!(1, "{}", f.to_string()) + Err(f) => $crate::crash!(1, "{}", f.to_string()) } ) ); @@ -197,7 +197,7 @@ macro_rules! snippet_list_join_oxford_comma { format!("{}, {} {}", $valOne, $conjunction, $valTwo) ); ($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => ( - format!("{}, {}", $valOne, snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*)) + format!("{}, {}", $valOne, $crate::snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*)) ); } @@ -207,7 +207,7 @@ macro_rules! snippet_list_join { format!("{} {} {}", $valOne, $conjunction, $valTwo) ); ($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => ( - format!("{}, {}", $valOne, snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*)) + format!("{}, {}", $valOne, $crate::snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*)) ); } @@ -225,10 +225,10 @@ macro_rules! msg_invalid_input { #[macro_export] macro_rules! msg_invalid_opt_use { ($about:expr, $flag:expr) => { - msg_invalid_input!(format!("The '{}' option {}", $flag, $about)) + $crate::msg_invalid_input!(format!("The '{}' option {}", $flag, $about)) }; ($about:expr, $long_flag:expr, $short_flag:expr) => { - msg_invalid_input!(format!( + $crate::msg_invalid_input!(format!( "The '{}' ('{}') option {}", $long_flag, $short_flag, $about )) @@ -238,10 +238,10 @@ macro_rules! msg_invalid_opt_use { #[macro_export] macro_rules! msg_opt_only_usable_if { ($clause:expr, $flag:expr) => { - msg_invalid_opt_use!(format!("only usable if {}", $clause), $flag) + $crate::msg_invalid_opt_use!(format!("only usable if {}", $clause), $flag) }; ($clause:expr, $long_flag:expr, $short_flag:expr) => { - msg_invalid_opt_use!( + $crate::msg_invalid_opt_use!( format!("only usable if {}", $clause), $long_flag, $short_flag @@ -252,13 +252,13 @@ macro_rules! msg_opt_only_usable_if { #[macro_export] macro_rules! msg_opt_invalid_should_be { ($expects:expr, $received:expr, $flag:expr) => { - msg_invalid_opt_use!( + $crate::msg_invalid_opt_use!( format!("expects {}, but was provided {}", $expects, $received), $flag ) }; ($expects:expr, $received:expr, $long_flag:expr, $short_flag:expr) => { - msg_invalid_opt_use!( + $crate::msg_invalid_opt_use!( format!("expects {}, but was provided {}", $expects, $received), $long_flag, $short_flag @@ -271,13 +271,13 @@ macro_rules! msg_opt_invalid_should_be { #[macro_export] macro_rules! msg_expects_one_of { ($valOne:expr $(, $remaining_values:expr)*) => ( - msg_invalid_input!(format!("expects one of {}", snippet_list_join!("or", $valOne $(, $remaining_values)*))) + $crate::msg_invalid_input!(format!("expects one of {}", $crate::snippet_list_join!("or", $valOne $(, $remaining_values)*))) ); } #[macro_export] macro_rules! msg_expects_no_more_than_one_of { ($valOne:expr $(, $remaining_values:expr)*) => ( - msg_invalid_input!(format!("expects no more than one of {}", snippet_list_join!("or", $valOne $(, $remaining_values)*))) ; + $crate::msg_invalid_input!(format!("expects no more than one of {}", $crate::snippet_list_join!("or", $valOne $(, $remaining_values)*))) ; ); } From c5792c2a0fbe64d020c5863f92b2b8bf98470b67 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 22:40:32 -0500 Subject: [PATCH 07/25] refactor ~ use `util_name!()` as clap::app::App name argument for all utils --- src/uu/arch/src/arch.rs | 2 +- src/uu/basename/src/basename.rs | 2 +- src/uu/cat/src/cat.rs | 2 +- src/uu/chgrp/src/chgrp.rs | 2 +- src/uu/chmod/src/chmod.rs | 2 +- src/uu/chown/src/chown.rs | 2 +- src/uu/chroot/src/chroot.rs | 2 +- src/uu/cksum/src/cksum.rs | 2 +- src/uu/comm/src/comm.rs | 2 +- src/uu/cp/src/cp.rs | 2 +- src/uu/csplit/src/csplit.rs | 2 +- src/uu/cut/src/cut.rs | 2 +- src/uu/date/src/date.rs | 2 +- src/uu/df/src/df.rs | 2 +- src/uu/dircolors/src/dircolors.rs | 2 +- src/uu/dirname/src/dirname.rs | 2 +- src/uu/du/src/du.rs | 2 +- src/uu/echo/src/echo.rs | 2 +- src/uu/expand/src/expand.rs | 2 +- src/uu/expr/src/expr.rs | 2 +- src/uu/factor/src/cli.rs | 2 +- src/uu/false/src/false.rs | 5 +++-- src/uu/fmt/src/fmt.rs | 2 +- src/uu/fold/src/fold.rs | 2 +- src/uu/groups/src/groups.rs | 2 +- src/uu/hashsum/src/hashsum.rs | 2 +- src/uu/head/src/head.rs | 4 ++-- src/uu/hostid/src/hostid.rs | 2 +- src/uu/hostname/src/hostname.rs | 2 +- src/uu/id/src/id.rs | 2 +- src/uu/install/src/install.rs | 2 +- src/uu/kill/src/kill.rs | 2 +- src/uu/link/src/link.rs | 2 +- src/uu/ln/src/ln.rs | 2 +- src/uu/logname/src/logname.rs | 2 +- src/uu/ls/src/ls.rs | 2 +- src/uu/mkdir/src/mkdir.rs | 2 +- src/uu/mkfifo/src/mkfifo.rs | 2 +- src/uu/mknod/src/mknod.rs | 2 +- src/uu/mktemp/src/mktemp.rs | 2 +- src/uu/more/src/more.rs | 2 +- src/uu/mv/src/mv.rs | 2 +- src/uu/nice/src/nice.rs | 2 +- src/uu/nl/src/nl.rs | 2 +- src/uu/nohup/src/nohup.rs | 2 +- src/uu/nproc/src/nproc.rs | 2 +- src/uu/numfmt/src/numfmt.rs | 2 +- src/uu/od/src/od.rs | 2 +- src/uu/paste/src/paste.rs | 2 +- src/uu/pathchk/src/pathchk.rs | 2 +- src/uu/pinky/src/pinky.rs | 2 +- src/uu/pr/src/pr.rs | 4 ++-- src/uu/printenv/src/printenv.rs | 2 +- src/uu/printf/src/printf.rs | 2 +- src/uu/ptx/src/ptx.rs | 2 +- src/uu/pwd/src/pwd.rs | 2 +- src/uu/readlink/src/readlink.rs | 2 +- src/uu/realpath/src/realpath.rs | 2 +- src/uu/relpath/src/relpath.rs | 2 +- src/uu/rm/src/rm.rs | 2 +- src/uu/rmdir/src/rmdir.rs | 2 +- src/uu/seq/src/seq.rs | 2 +- src/uu/shred/src/shred.rs | 2 +- src/uu/shuf/src/shuf.rs | 2 +- src/uu/sleep/src/sleep.rs | 2 +- src/uu/sort/src/sort.rs | 2 +- src/uu/split/src/split.rs | 2 +- src/uu/stat/src/stat.rs | 2 +- src/uu/stdbuf/src/stdbuf.rs | 2 +- src/uu/sum/src/sum.rs | 2 +- src/uu/sync/src/sync.rs | 2 +- src/uu/tac/src/tac.rs | 2 +- src/uu/tail/src/tail.rs | 2 +- src/uu/tee/src/tee.rs | 2 +- src/uu/test/src/test.rs | 4 ++-- src/uu/touch/src/touch.rs | 2 +- src/uu/tr/src/tr.rs | 2 +- src/uu/true/src/true.rs | 4 ++-- src/uu/truncate/src/truncate.rs | 2 +- src/uu/tsort/src/tsort.rs | 2 +- src/uu/tty/src/tty.rs | 2 +- src/uu/uname/src/uname.rs | 2 +- src/uu/unexpand/src/unexpand.rs | 2 +- src/uu/uniq/src/uniq.rs | 2 +- src/uu/unlink/src/unlink.rs | 2 +- src/uu/uptime/src/uptime.rs | 2 +- src/uu/users/src/users.rs | 2 +- src/uu/wc/src/wc.rs | 2 +- src/uu/who/src/who.rs | 2 +- 89 files changed, 95 insertions(+), 94 deletions(-) diff --git a/src/uu/arch/src/arch.rs b/src/uu/arch/src/arch.rs index 94ec97e98..30adbaad9 100644 --- a/src/uu/arch/src/arch.rs +++ b/src/uu/arch/src/arch.rs @@ -27,7 +27,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help(SUMMARY) diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index 5450ee3f2..26fb67c54 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -93,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(SUMMARY) .arg( diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index b9d07bcda..cb12830a4 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -234,7 +234,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(SYNTAX) diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index dd851c504..db1e20e57 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -197,7 +197,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(VERSION) .about(ABOUT) .arg( diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index d89827c97..d39ac4556 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -116,7 +116,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index 7df263c5d..50c651e1f 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -165,7 +165,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 2c0f8522c..b548b7734 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -92,7 +92,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .usage(SYNTAX) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index e88cc78b3..8173fa451 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .about(SUMMARY) diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index aa10432a2..69db9c556 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -148,7 +148,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 7c67649c2..8920cd439 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -293,7 +293,7 @@ static DEFAULT_ATTRIBUTES: &[Attribute] = &[ ]; pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg(Arg::with_name(options::TARGET_DIRECTORY) diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 048ec80d8..039501401 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -739,7 +739,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(SUMMARY) .arg( diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index e33b8a2fe..6410b9efc 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -548,7 +548,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(SYNTAX) diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 042daa616..3d2a8c6d0 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -253,7 +253,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index cdfdf0b2d..9977370c4 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -427,7 +427,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 70b609e31..27b43b9a0 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -153,7 +153,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(SUMMARY) .after_help(LONG_HELP) diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index e7dcc2195..d6e09acc1 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -86,7 +86,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .about(ABOUT) .version(crate_version!()) .arg( diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index d85cc941c..02a05b911 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -625,7 +625,7 @@ fn parse_depth(max_depth_str: Option<&str>, summarize: bool) -> UResult App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(SUMMARY) .after_help(LONG_HELP) diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index aae1ad10d..d34460df0 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -132,7 +132,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) // TrailingVarArg specifies the final positional argument is a VarArg // and it doesn't attempts the parse any further args. diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index d5c37ce21..a821aed33 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -178,7 +178,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index 92c15565d..b37e1ced6 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -18,7 +18,7 @@ const VERSION: &str = "version"; const HELP: &str = "help"; pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .arg(Arg::with_name(VERSION).long(VERSION)) .arg(Arg::with_name(HELP).long(HELP)) } diff --git a/src/uu/factor/src/cli.rs b/src/uu/factor/src/cli.rs index 7963f162f..628ded969 100644 --- a/src/uu/factor/src/cli.rs +++ b/src/uu/factor/src/cli.rs @@ -75,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(SUMMARY) .arg(Arg::with_name(options::NUMBER).multiple(true)) diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 170788898..8f7710912 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -9,7 +9,8 @@ extern crate uucore; use clap::App; -use uucore::{error::UResult, executable}; +use uucore::error::UResult; +use uucore::util_name; #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { @@ -18,5 +19,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) } diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index 8c2c8d9d9..87febb124 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -211,7 +211,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 1dbc8cdc7..a2321d5ee 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(SYNTAX) diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index a40d1a490..a7c989ddf 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -85,7 +85,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index d9feb6648..332e08009 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -342,7 +342,7 @@ pub fn uu_app_common() -> App<'static, 'static> { const TEXT_HELP: &str = "read in text mode"; #[cfg(not(windows))] const TEXT_HELP: &str = "read in text mode (default)"; - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about("Compute and check message digests.") .arg( diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index e17e17034..11ea56449 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -9,7 +9,7 @@ use clap::{crate_version, App, Arg}; use std::convert::TryFrom; use std::ffi::OsString; use std::io::{self, ErrorKind, Read, Seek, SeekFrom, Write}; -use uucore::{crash, executable, show_error, show_error_custom_description}; +use uucore::{crash, show_error_custom_description, util_name}; const EXIT_FAILURE: i32 = 1; const EXIT_SUCCESS: i32 = 0; @@ -41,7 +41,7 @@ use lines::zlines; use take::take_all_but; pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .usage(USAGE) diff --git a/src/uu/hostid/src/hostid.rs b/src/uu/hostid/src/hostid.rs index b0f68968d..e593ff7ee 100644 --- a/src/uu/hostid/src/hostid.rs +++ b/src/uu/hostid/src/hostid.rs @@ -29,7 +29,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .usage(SYNTAX) } diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index 045e43045..e42629eff 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -73,7 +73,7 @@ fn execute(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 16c665273..ce2d8eaf1 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -347,7 +347,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index cbbe9c18b..33a21be88 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -202,7 +202,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index b3f5010ca..e9ec70964 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -76,7 +76,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/link/src/link.rs b/src/uu/link/src/link.rs index ad7702044..5344eb9c8 100644 --- a/src/uu/link/src/link.rs +++ b/src/uu/link/src/link.rs @@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 7010ff5e4..a9a8379a0 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -196,7 +196,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 4a6f43418..45187be18 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -56,7 +56,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(SUMMARY) } diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 450acf8cd..6e49e7ef9 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -618,7 +618,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about( "By default, ls will list the files and contents of any directories on \ diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index a99867570..8d492a93c 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index ea0906567..10ea8337c 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 8cc7db908..72b35cd33 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -145,7 +145,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .usage(USAGE) .after_help(LONG_HELP) diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index e1dd604a0..645c5ac28 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -134,7 +134,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index ecc779ba6..ee03c0d8a 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -93,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .about("A file perusal filter for CRT viewing.") .version(crate_version!()) .arg( diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 166e8cb1a..5f7431203 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -133,7 +133,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index 49efe32e0..62565fc5c 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -101,7 +101,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .setting(AppSettings::TrailingVarArg) .version(crate_version!()) .arg( diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 81e76aa26..d5ea18f8a 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -143,7 +143,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index acc101e4e..60654672d 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -71,7 +71,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index 1f284685b..ae8e66492 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 01f12c51b..4f9d90a6c 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -175,7 +175,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 359531d4e..b37990fd5 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -252,7 +252,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> clap::App<'static, 'static> { - clap::App::new(executable!()) + clap::App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .usage(USAGE) diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 7f7969687..801de50dc 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -52,7 +52,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 7f728667f..44e4ed4ac 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -96,7 +96,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 16bcfd3c9..58c4f56ed 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -130,7 +130,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index d6b9e8ca3..9ee5158ec 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -23,7 +23,7 @@ use std::fs::{metadata, File}; use std::io::{stdin, stdout, BufRead, BufReader, Lines, Read, Stdout, Write}; #[cfg(unix)] use std::os::unix::fs::FileTypeExt; -use uucore::executable; +use uucore::util_name; type IOError = std::io::Error; @@ -170,7 +170,7 @@ quick_error! { pub fn uu_app() -> clap::App<'static, 'static> { // TODO: migrate to clap to get more shell completions - clap::App::new(executable!()) + clap::App::new(util_name!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/printenv/src/printenv.rs b/src/uu/printenv/src/printenv.rs index 6e0ca7157..7164f5092 100644 --- a/src/uu/printenv/src/printenv.rs +++ b/src/uu/printenv/src/printenv.rs @@ -55,7 +55,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index efa9aea57..bc672156f 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -303,7 +303,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .arg(Arg::with_name(VERSION).long(VERSION)) .arg(Arg::with_name(HELP).long(HELP)) } diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 01b14bc4d..4f16af470 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -659,7 +659,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(BRIEF) diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index 37effe618..f29a3abfa 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -66,7 +66,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index 826fa0254..7ae2f9423 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -98,7 +98,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index fe2ad4ccc..34b2640ab 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -55,7 +55,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/relpath/src/relpath.rs b/src/uu/relpath/src/relpath.rs index cb0fba7cc..e27ee0ce9 100644 --- a/src/uu/relpath/src/relpath.rs +++ b/src/uu/relpath/src/relpath.rs @@ -82,7 +82,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 259d1ab39..4c44f59ee 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -140,7 +140,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index 8dbaf79a8..3acfca773 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -53,7 +53,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 50a93d3af..589e8450d 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -163,7 +163,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .setting(AppSettings::AllowLeadingHyphen) .version(crate_version!()) .about(ABOUT) diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 90336ea95..43428caf6 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -330,7 +330,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help(AFTER_HELP) diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 4690d1c6e..7f69a5fe9 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -115,7 +115,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .template(TEMPLATE) diff --git a/src/uu/sleep/src/sleep.rs b/src/uu/sleep/src/sleep.rs index 127804a9f..c34d4f7b7 100644 --- a/src/uu/sleep/src/sleep.rs +++ b/src/uu/sleep/src/sleep.rs @@ -49,7 +49,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index e0b445782..c31c47eb9 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1287,7 +1287,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index ccc98ee5e..8e7cb5d6d 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -127,7 +127,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about("Create output files containing consecutive or interleaved sections of input") // strategy (mutually exclusive) diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index c56971f6b..d4e9818d5 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -963,7 +963,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 7460a2cb2..469fffbdc 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -185,7 +185,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 0ce612859..b4b2294aa 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -140,7 +140,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 4fcdf49f9..5109bf24b 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -193,7 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 01cf09215..70fa04622 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 471c1a404..106c1c5db 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about("output the last part of files") // TODO: add usage diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index a207dee63..bf9334677 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -57,7 +57,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .after_help("If a FILE is -, it refers to a file named - .") diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index bed1472e2..939e13ab9 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -14,7 +14,7 @@ use clap::{crate_version, App, AppSettings}; use parser::{parse, Symbol}; use std::ffi::{OsStr, OsString}; use std::path::Path; -use uucore::executable; +use uucore::util_name; const USAGE: &str = "test EXPRESSION or: test @@ -87,7 +87,7 @@ the version described here. Please refer to your shell's documentation for details about the options it supports."; pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .setting(AppSettings::DisableHelpFlags) .setting(AppSettings::DisableVersion) } diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 49efa676a..92c0080fa 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -129,7 +129,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 6dd81badf..390511ec4 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -312,7 +312,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index f84a89176..07e075175 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -10,7 +10,7 @@ extern crate uucore; use clap::App; use uucore::error::UResult; -use uucore::executable; +use uucore::util_name; #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { @@ -19,5 +19,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) } diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index bb7aa61d4..7b7a55f33 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -133,7 +133,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 0a323f837..c2416afb4 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -90,7 +90,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .usage(USAGE) .about(SUMMARY) diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 7412cdf45..7c6f73dd4 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -78,7 +78,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index abd50d1b8..2b16c85ec 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -119,7 +119,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg(Arg::with_name(options::ALL) diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 50e3f186d..4a4c50feb 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -102,7 +102,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 20639c850..288ecf105 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -281,7 +281,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index 49f17cb12..7c0e596fb 100644 --- a/src/uu/unlink/src/unlink.rs +++ b/src/uu/unlink/src/unlink.rs @@ -95,7 +95,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg(Arg::with_name(OPT_PATH).hidden(true).multiple(true)) diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index 35270093c..06dd93a24 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index ef878497c..91168644c 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -65,7 +65,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg(Arg::with_name(ARG_FILES).takes_value(true).max_values(1)) diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 0bcc66664..afdf8b7de 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -164,7 +164,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 6a9c88710..557a4efd6 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -160,7 +160,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( From 894d9a068cf83b456e596e35f4316b23ebda2ff2 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 22:44:43 -0500 Subject: [PATCH 08/25] 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() } From 23b68d80bad807df1dcb6dd8e4d925988744df05 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 30 Jun 2021 23:03:14 -0500 Subject: [PATCH 09/25] refactor ~ `usage()` instead of `get_usage()` --- src/uu/base32/src/base32.rs | 4 ++-- src/uu/base64/src/base64.rs | 4 ++-- src/uu/basename/src/basename.rs | 4 ++-- src/uu/chgrp/src/chgrp.rs | 4 ++-- src/uu/chmod/src/chmod.rs | 4 ++-- src/uu/chown/src/chown.rs | 4 ++-- src/uu/comm/src/comm.rs | 4 ++-- src/uu/cp/src/cp.rs | 4 ++-- src/uu/csplit/src/csplit.rs | 4 ++-- src/uu/df/src/df.rs | 4 ++-- src/uu/dircolors/src/dircolors.rs | 4 ++-- src/uu/dirname/src/dirname.rs | 4 ++-- src/uu/du/src/du.rs | 4 ++-- src/uu/expand/src/expand.rs | 4 ++-- src/uu/fmt/src/fmt.rs | 4 ++-- src/uu/groups/src/groups.rs | 4 ++-- src/uu/hostname/src/hostname.rs | 5 +++-- src/uu/id/src/id.rs | 4 ++-- src/uu/install/src/install.rs | 4 ++-- src/uu/link/src/link.rs | 4 ++-- src/uu/ln/src/ln.rs | 8 ++++---- src/uu/logname/src/logname.rs | 4 ++-- src/uu/ls/src/ls.rs | 4 ++-- src/uu/mkdir/src/mkdir.rs | 4 ++-- src/uu/mktemp/src/mktemp.rs | 4 ++-- src/uu/mv/src/mv.rs | 4 ++-- src/uu/nice/src/nice.rs | 4 ++-- src/uu/nohup/src/nohup.rs | 4 ++-- src/uu/nproc/src/nproc.rs | 4 ++-- src/uu/numfmt/src/numfmt.rs | 4 ++-- src/uu/pathchk/src/pathchk.rs | 4 ++-- src/uu/pinky/src/pinky.rs | 4 ++-- src/uu/printenv/src/printenv.rs | 4 ++-- src/uu/pwd/src/pwd.rs | 4 ++-- src/uu/readlink/src/readlink.rs | 4 ++-- src/uu/realpath/src/realpath.rs | 4 ++-- src/uu/relpath/src/relpath.rs | 4 ++-- src/uu/rm/src/rm.rs | 4 ++-- src/uu/rmdir/src/rmdir.rs | 4 ++-- src/uu/seq/src/seq.rs | 4 ++-- src/uu/shred/src/shred.rs | 4 ++-- src/uu/sleep/src/sleep.rs | 4 ++-- src/uu/sort/src/sort.rs | 4 ++-- src/uu/split/src/split.rs | 6 +++--- src/uu/stat/src/stat.rs | 4 ++-- src/uu/stdbuf/src/stdbuf.rs | 4 ++-- src/uu/sync/src/sync.rs | 4 ++-- src/uu/tee/src/tee.rs | 4 ++-- src/uu/timeout/src/timeout.rs | 4 ++-- src/uu/touch/src/touch.rs | 4 ++-- src/uu/tr/src/tr.rs | 4 ++-- src/uu/truncate/src/truncate.rs | 4 ++-- src/uu/tty/src/tty.rs | 4 ++-- src/uu/uniq/src/uniq.rs | 4 ++-- src/uu/unlink/src/unlink.rs | 4 ++-- src/uu/uptime/src/uptime.rs | 4 ++-- src/uu/users/src/users.rs | 4 ++-- src/uu/wc/src/wc.rs | 4 ++-- src/uu/who/src/who.rs | 4 ++-- 59 files changed, 122 insertions(+), 121 deletions(-) diff --git a/src/uu/base32/src/base32.rs b/src/uu/base32/src/base32.rs index 9a29717ac..8e02f03e0 100644 --- a/src/uu/base32/src/base32.rs +++ b/src/uu/base32/src/base32.rs @@ -28,13 +28,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); static BASE_CMD_PARSE_ERROR: i32 = 1; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { let format = Format::Base32; - let usage = get_usage(); + let usage = usage(); let name = executable!(); let config_result: Result = diff --git a/src/uu/base64/src/base64.rs b/src/uu/base64/src/base64.rs index 71ed44e6e..48aee537d 100644 --- a/src/uu/base64/src/base64.rs +++ b/src/uu/base64/src/base64.rs @@ -29,13 +29,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); static BASE_CMD_PARSE_ERROR: i32 = 1; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { let format = Format::Base64; - let usage = get_usage(); + let usage = usage(); let name = executable!(); let config_result: Result = base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage); diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index aa1e2fa2d..f3c9f5391 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -17,7 +17,7 @@ use uucore::InvalidEncodingHandling; static SUMMARY: &str = "Print NAME with any leading directory components removed If specified, also remove a trailing SUFFIX"; -fn get_usage() -> String { +fn usage() -> String { format!( "{0} NAME [SUFFIX] {0} OPTION... NAME...", @@ -36,7 +36,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let args = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - let usage = get_usage(); + let usage = usage(); // // Argument parsing // diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index db1e20e57..11a45c90a 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -59,7 +59,7 @@ const FTS_COMFOLLOW: u8 = 1; const FTS_PHYSICAL: u8 = 1 << 1; const FTS_LOGICAL: u8 = 1 << 2; -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... GROUP FILE...\n {0} [OPTION]... --reference=RFILE FILE...", executable!() @@ -71,7 +71,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - let usage = get_usage(); + let usage = usage(); let mut app = uu_app().usage(&usage[..]); diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index d39ac4556..e1d8b32e4 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -36,7 +36,7 @@ mod options { pub const FILE: &str = "FILE"; } -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... MODE[,MODE]... FILE... or: {0} [OPTION]... OCTAL-MODE FILE... @@ -58,7 +58,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE"). let mode_had_minus_prefix = strip_minus_from_mode(&mut args); - let usage = get_usage(); + let usage = usage(); let after_help = get_long_usage(); let matches = uu_app() diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index 50c651e1f..a5d7c5ac7 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -61,7 +61,7 @@ const FTS_COMFOLLOW: u8 = 1; const FTS_PHYSICAL: u8 = 1 << 1; const FTS_LOGICAL: u8 = 1 << 2; -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... [OWNER][:[GROUP]] FILE...\n{0} [OPTION]... --reference=RFILE FILE...", executable!() @@ -74,7 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index 69db9c556..36238cd5f 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -31,7 +31,7 @@ mod options { pub const FILE_2: &str = "FILE2"; } -fn get_usage() -> String { +fn usage() -> String { format!("{} [OPTION]... FILE1 FILE2", executable!()) } @@ -132,7 +132,7 @@ fn open_file(name: &str) -> io::Result { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let args = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 542e9bfee..406f6757d 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -218,7 +218,7 @@ static LONG_HELP: &str = ""; static EXIT_OK: i32 = 0; static EXIT_ERR: i32 = 1; -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... [-T] SOURCE DEST {0} [OPTION]... SOURCE... DIRECTORY @@ -465,7 +465,7 @@ pub fn uu_app() -> App<'static, 'static> { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app() .after_help(&*format!( "{}\n{}", diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 039501401..409b17b98 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -34,7 +34,7 @@ mod options { pub const PATTERN: &str = "pattern"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... FILE PATTERN...", executable!()) } @@ -706,7 +706,7 @@ mod tests { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let args = args .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 9977370c4..4ffa8b532 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -79,7 +79,7 @@ struct Filesystem { usage: FsUsage, } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]...", executable!()) } @@ -284,7 +284,7 @@ impl UError for DfError { #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let paths: Vec = matches diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 27b43b9a0..90b48c301 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -62,7 +62,7 @@ pub fn guess_syntax() -> OutputFmt { } } -fn get_usage() -> String { +fn usage() -> String { format!("{0} {1}", executable!(), SYNTAX) } @@ -71,7 +71,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(&args); diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index d6e09acc1..3162bef48 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -20,7 +20,7 @@ mod options { pub const DIR: &str = "dir"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION] NAME...", executable!()) } @@ -37,7 +37,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - let usage = get_usage(); + let usage = usage(); let after_help = get_long_usage(); let matches = uu_app() diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 6160f5490..56f412ffb 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -392,7 +392,7 @@ fn convert_size_other(size: u64, _multiplier: u64, block_size: u64) -> String { format!("{}", ((size as f64) / (block_size as f64)).ceil()) } -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... [FILE]... {0} [OPTION]... --files0-from=F", @@ -456,7 +456,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index a821aed33..29de6ae44 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -32,7 +32,7 @@ static LONG_HELP: &str = ""; static DEFAULT_TABSTOP: usize = 8; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]...", executable!()) } @@ -170,7 +170,7 @@ impl Options { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); expand(Options::new(&matches)); diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index 87febb124..80f74cf84 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -50,7 +50,7 @@ static OPT_TAB_WIDTH: &str = "tab-width"; static ARG_FILES: &str = "files"; -fn get_usage() -> String { +fn usage() -> String { format!("{} [OPTION]... [FILE]...", executable!()) } @@ -75,7 +75,7 @@ pub struct FmtOptions { #[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index a7c989ddf..fe1065cc1 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -28,12 +28,12 @@ static ABOUT: &str = "Print group memberships for each USERNAME or, \ if no USERNAME is specified, for\nthe current process \ (which may differ if the groups data‐base has changed)."; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [USERNAME]...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index e42629eff..2b7deb565 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -53,11 +53,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { result } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [HOSTNAME]", executable!()) } + fn execute(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); match matches.value_of(OPT_HOST) { diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index ce2d8eaf1..16c521ea3 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -76,7 +76,7 @@ mod options { pub const ARG_USERS: &str = "USER"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [USER]...", executable!()) } @@ -127,7 +127,7 @@ struct State { #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); let after_help = get_description(); let matches = uu_app() diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 33a21be88..5ee103e0f 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -172,7 +172,7 @@ static OPT_CONTEXT: &str = "context"; static ARG_FILES: &str = "files"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]...", executable!()) } @@ -182,7 +182,7 @@ fn get_usage() -> String { /// #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/link/src/link.rs b/src/uu/link/src/link.rs index 5344eb9c8..d06025815 100644 --- a/src/uu/link/src/link.rs +++ b/src/uu/link/src/link.rs @@ -19,7 +19,7 @@ pub mod options { pub static FILES: &str = "FILES"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} FILE1 FILE2", executable!()) } @@ -31,7 +31,7 @@ pub fn normalize_error_message(e: Error) -> String { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let files: Vec<_> = matches diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 568c97e45..572c68379 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -92,7 +92,7 @@ impl UError for LnError { } } -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... [-T] TARGET LINK_NAME (1st form) {0} [OPTION]... TARGET (2nd form) @@ -102,7 +102,7 @@ fn get_usage() -> String { ) } -fn get_long_usage() -> String { +fn long_usage() -> String { String::from( " In the 1st form, create a link to TARGET with the name LINK_NAME. In the 2nd form, create a link to TARGET in the current directory. @@ -136,8 +136,8 @@ static ARG_FILES: &str = "files"; #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); - let long_usage = get_long_usage(); + let usage = usage(); + let long_usage = long_usage(); let matches = uu_app() .usage(&usage[..]) diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 45187be18..095f3fc84 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -35,7 +35,7 @@ fn get_userlogin() -> Option { static SUMMARY: &str = "Print user's login name"; -fn get_usage() -> String { +fn usage() -> String { String::from(executable!()) } @@ -44,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let _ = uu_app().usage(&usage[..]).get_matches_from(args); match get_userlogin() { diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 6e49e7ef9..f02a53738 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -46,7 +46,7 @@ use unicode_width::UnicodeWidthStr; use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; use uucore::{fs::display_permissions, version_cmp::version_cmp}; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]...", executable!()) } @@ -603,7 +603,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let app = uu_app().usage(&usage[..]); diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 8d492a93c..e9aa4bc22 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -22,13 +22,13 @@ mod options { pub const DIRS: &str = "dirs"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [USER]", executable!()) } #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); // Linux-specific options, not implemented // opts.optflag("Z", "context", "set SELinux security context" + diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 645c5ac28..52d60d140 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -36,7 +36,7 @@ static OPT_T: &str = "t"; static ARG_TEMPLATE: &str = "template"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [TEMPLATE]", executable!()) } @@ -74,7 +74,7 @@ impl Display for MkTempError { #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index c064a2244..1c25e653c 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -58,7 +58,7 @@ static OPT_VERBOSE: &str = "verbose"; static ARG_FILES: &str = "files"; -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... [-T] SOURCE DEST {0} [OPTION]... SOURCE... DIRECTORY @@ -68,7 +68,7 @@ fn get_usage() -> String { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app() .after_help(&*format!( diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index 3b62d8058..c071a875f 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -22,7 +22,7 @@ pub mod options { pub static COMMAND: &str = "COMMAND"; } -fn get_usage() -> String { +fn usage() -> String { format!( " {0} [OPTIONS] [COMMAND [ARGS]] @@ -36,7 +36,7 @@ process).", } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 60654672d..a6f08e806 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -40,7 +40,7 @@ mod options { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let args = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); @@ -156,7 +156,7 @@ fn find_stdout() -> File { } } -fn get_usage() -> String { +fn usage() -> String { format!("{0} COMMAND [ARG]...\n {0} FLAG", executable!()) } diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index ae8e66492..427a3cd2f 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -27,12 +27,12 @@ static OPT_IGNORE: &str = "ignore"; static ABOUT: &str = "Print the number of cores available to the current process."; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTIONS]...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let mut ignore = match matches.value_of(OPT_IGNORE) { diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 4f9d90a6c..6012bbf82 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -50,7 +50,7 @@ FIELDS supports cut(1) style field ranges: Multiple fields/ranges can be separated with commas "; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [NUMBER]...", executable!()) } @@ -154,7 +154,7 @@ fn parse_options(args: &ArgMatches) -> Result { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 46edf0850..4d257a771 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -39,12 +39,12 @@ mod options { const POSIX_PATH_MAX: usize = 256; const POSIX_NAME_MAX: usize = 14; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... NAME...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let args = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 58c4f56ed..4aad2c07d 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -40,7 +40,7 @@ mod options { pub const USER: &str = "user"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [USER]...", executable!()) } @@ -57,7 +57,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let after_help = get_long_usage(); let matches = uu_app() diff --git a/src/uu/printenv/src/printenv.rs b/src/uu/printenv/src/printenv.rs index 7164f5092..0e86f1012 100644 --- a/src/uu/printenv/src/printenv.rs +++ b/src/uu/printenv/src/printenv.rs @@ -19,12 +19,12 @@ static OPT_NULL: &str = "null"; static ARG_VARIABLES: &str = "variables"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [VARIABLE]... [OPTION]...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index f29a3abfa..bfdfafd13 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -34,13 +34,13 @@ pub fn absolute_path(path: &Path) -> io::Result { Ok(path_buf) } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... FILE...", executable!()) } #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index 4bfac4630..b86dff162 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -29,12 +29,12 @@ const OPT_ZERO: &str = "zero"; const ARG_FILES: &str = "files"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let mut no_newline = matches.is_present(OPT_NO_NEWLINE); diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index 34b2640ab..494fe41dc 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -22,12 +22,12 @@ static OPT_ZERO: &str = "zero"; static ARG_FILES: &str = "files"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... FILE...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/relpath/src/relpath.rs b/src/uu/relpath/src/relpath.rs index e27ee0ce9..b7fa8991c 100644 --- a/src/uu/relpath/src/relpath.rs +++ b/src/uu/relpath/src/relpath.rs @@ -25,7 +25,7 @@ mod options { pub const FROM: &str = "FROM"; } -fn get_usage() -> String { +fn usage() -> String { format!("{} [-d DIR] TO [FROM]", executable!()) } @@ -33,7 +33,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let args = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 4c44f59ee..4b435807b 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -52,7 +52,7 @@ static OPT_VERBOSE: &str = "verbose"; static ARG_FILES: &str = "files"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... FILE...", executable!()) } @@ -74,7 +74,7 @@ fn get_long_usage() -> String { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let long_usage = get_long_usage(); let matches = uu_app() diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index 3acfca773..880300a7a 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -26,12 +26,12 @@ static ENOTDIR: i32 = 20; #[cfg(windows)] static ENOTDIR: i32 = 267; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... DIRECTORY...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index ae81aa71d..2042cf23f 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -22,7 +22,7 @@ static OPT_WIDTHS: &str = "widths"; static ARG_NUMBERS: &str = "numbers"; -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... LAST {0} [OPTION]... FIRST LAST @@ -86,7 +86,7 @@ impl FromStr for Number { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let numbers = matches.values_of(ARG_NUMBERS).unwrap().collect::>(); diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 43428caf6..936577f01 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -213,7 +213,7 @@ static ABOUT: &str = "Overwrite the specified FILE(s) repeatedly, in order to ma for even very expensive hardware probing to recover the data. "; -fn get_usage() -> String { +fn usage() -> String { format!("{} [OPTION]... FILE...", executable!()) } @@ -270,7 +270,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let app = uu_app().usage(&usage[..]); diff --git a/src/uu/sleep/src/sleep.rs b/src/uu/sleep/src/sleep.rs index c34d4f7b7..624e65901 100644 --- a/src/uu/sleep/src/sleep.rs +++ b/src/uu/sleep/src/sleep.rs @@ -26,7 +26,7 @@ mod options { pub const NUMBER: &str = "NUMBER"; } -fn get_usage() -> String { +fn usage() -> String { format!( "{0} {1}[SUFFIX]... \n {0} OPTION", executable!(), @@ -36,7 +36,7 @@ fn get_usage() -> String { #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index c31c47eb9..78b6f8b64 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1055,7 +1055,7 @@ impl FieldSelector { } } -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... [FILE]... Write the sorted concatenation of all FILE(s) to standard output. @@ -1081,7 +1081,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let mut settings: GlobalSettings = Default::default(); let matches = match uu_app().usage(&usage[..]).get_matches_from_safe(args) { diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 8e7cb5d6d..bc38818b9 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -36,7 +36,7 @@ static OPT_VERBOSE: &str = "verbose"; static ARG_INPUT: &str = "input"; static ARG_PREFIX: &str = "prefix"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [INPUT [PREFIX]]", NAME) } fn get_long_usage() -> String { @@ -47,12 +47,12 @@ fn get_long_usage() -> String { Output fixed-size pieces of INPUT to PREFIXaa, PREFIX ab, ...; default size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is -, read standard input.", - get_usage() + usage() ) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let long_usage = get_long_usage(); let matches = uu_app() diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index d4e9818d5..4a12e4fb7 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -882,7 +882,7 @@ impl Stater { } } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... FILE...", executable!()) } @@ -945,7 +945,7 @@ for details about the options it supports. } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let long_usage = get_long_usage(); let matches = uu_app() diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 60f42102d..bac5040cf 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -47,7 +47,7 @@ mod options { pub const COMMAND: &str = "command"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} OPTION... COMMAND", executable!()) } @@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let args = args .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 5109bf24b..123167db7 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -159,12 +159,12 @@ mod platform { } } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... FILE...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index bf9334677..2f1b17ebe 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -32,12 +32,12 @@ struct Options { files: Vec, } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index 464414c5e..e0fbe8a54 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -22,7 +22,7 @@ use uucore::InvalidEncodingHandling; static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION."; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION] DURATION COMMAND...", executable!()) } @@ -100,7 +100,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - let usage = get_usage(); + let usage = usage(); let app = uu_app().usage(&usage[..]); diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 92c0080fa..bdb65683f 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -47,13 +47,13 @@ fn local_tm_to_filetime(tm: time::Tm) -> FileTime { FileTime::from_unix_time(ts.sec as i64, ts.nsec as u32) } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [USER]", executable!()) } #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 390511ec4..ddb866393 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -228,7 +228,7 @@ fn translate_input( } } -fn get_usage() -> String { +fn usage() -> String { format!("{} [OPTION]... SET1 [SET2]", executable!()) } @@ -243,7 +243,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - let usage = get_usage(); + let usage = usage(); let after_help = get_long_usage(); let matches = uu_app() diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index 7b7a55f33..c5f9fb5b7 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -63,7 +63,7 @@ pub mod options { pub static ARG_FILES: &str = "files"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [FILE]...", executable!()) } @@ -90,7 +90,7 @@ fn get_long_usage() -> String { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let long_usage = get_long_usage(); let matches = uu_app() diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 7c6f73dd4..df6c43a27 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -23,12 +23,12 @@ mod options { pub const SILENT: &str = "silent"; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let args = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 288ecf105..fd8b4019b 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -221,7 +221,7 @@ fn opt_parsed(opt_name: &str, matches: &ArgMatches) -> Option { }) } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [INPUT [OUTPUT]]...", executable!()) } @@ -235,7 +235,7 @@ fn get_long_usage() -> String { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let long_usage = get_long_usage(); let matches = uu_app() diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index 5f96cf429..0601b3e54 100644 --- a/src/uu/unlink/src/unlink.rs +++ b/src/uu/unlink/src/unlink.rs @@ -22,7 +22,7 @@ use uucore::InvalidEncodingHandling; static ABOUT: &str = "Unlink the file at [FILE]."; static OPT_PATH: &str = "FILE"; -fn get_usage() -> String { +fn usage() -> String { format!("{} [OPTION]... FILE", executable!()) } @@ -31,7 +31,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index 06dd93a24..33f3ec965 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -32,12 +32,12 @@ extern "C" { fn GetTickCount() -> uucore::libc::uint32_t; } -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]...", executable!()) } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let (boot_time, user_count) = process_utmpx(); diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index 91168644c..3f081f891 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -18,7 +18,7 @@ static ABOUT: &str = "Print the user names of users currently logged in to the c static ARG_FILES: &str = "files"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [FILE]", executable!()) } @@ -31,7 +31,7 @@ If FILE is not specified, use {}. /var/log/wtmp as FILE is common.", } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let after_help = get_long_usage(); let matches = uu_app() diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index afdf8b7de..e21eb0b7e 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -95,7 +95,7 @@ pub mod options { static ARG_FILES: &str = "files"; -fn get_usage() -> String { +fn usage() -> String { format!( "{0} [OPTION]... [FILE]... With no FILE, or when FILE is -, read standard input.", @@ -132,7 +132,7 @@ impl Input { } pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 557a4efd6..558d42f1b 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -44,7 +44,7 @@ static RUNLEVEL_HELP: &str = "print current runlevel"; #[cfg(not(target_os = "linux"))] static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)"; -fn get_usage() -> String { +fn usage() -> String { format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", executable!()) } @@ -61,7 +61,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let usage = get_usage(); + let usage = usage(); let after_help = get_long_usage(); let matches = uu_app() From eb13533e4ea93814ac2d37fc982699343ecd0672 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Mon, 26 Jul 2021 20:25:41 -0500 Subject: [PATCH 10/25] refactor/uucore ~ replace `executable_name!()` with `util_name!()` in standard messaging --- src/uucore/src/lib/macros.rs | 10 +++++----- src/uucore/src/lib/mods/coreopts.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 715752c84..06aad6f36 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -55,7 +55,7 @@ macro_rules! show( ($err:expr) => ({ let e = $err; uucore::error::set_exit_code(e.code()); - eprintln!("{}: {}", $crate::executable_name!(), e); + eprintln!("{}: {}", $crate::util_name!(), e); }) ); @@ -72,7 +72,7 @@ macro_rules! show_if_err( #[macro_export] macro_rules! show_error( ($($args:tt)+) => ({ - eprint!("{}: ", $crate::executable_name!()); + eprint!("{}: ", $crate::util_name!()); eprintln!($($args)+); }) ); @@ -81,7 +81,7 @@ macro_rules! show_error( #[macro_export] macro_rules! show_error_custom_description ( ($err:expr,$($args:tt)+) => ({ - eprint!("{}: {}: ", $crate::executable_name!(), $err); + eprint!("{}: {}: ", $crate::util_name!(), $err); eprintln!($($args)+); }) ); @@ -89,7 +89,7 @@ macro_rules! show_error_custom_description ( #[macro_export] macro_rules! show_warning( ($($args:tt)+) => ({ - eprint!("{}: warning: ", $crate::executable_name!()); + eprint!("{}: warning: ", $crate::util_name!()); eprintln!($($args)+); }) ); @@ -98,7 +98,7 @@ macro_rules! show_warning( #[macro_export] macro_rules! show_usage_error( ($($args:tt)+) => ({ - eprint!("{}: ", $crate::executable_name!()); + eprint!("{}: ", $crate::util_name!()); eprintln!($($args)+); eprintln!("Try `{:?} --help` for more information.", $crate::executable!()); }) diff --git a/src/uucore/src/lib/mods/coreopts.rs b/src/uucore/src/lib/mods/coreopts.rs index f3fb77335..b81ef7e5a 100644 --- a/src/uucore/src/lib/mods/coreopts.rs +++ b/src/uucore/src/lib/mods/coreopts.rs @@ -120,7 +120,7 @@ impl<'a> CoreOptions<'a> { macro_rules! app { ($syntax: expr, $summary: expr, $long_help: expr) => { uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText { - name: executable!(), + name: util_name!(), version: env!("CARGO_PKG_VERSION"), syntax: $syntax, summary: $summary, @@ -130,7 +130,7 @@ macro_rules! app { }; ($syntax: expr, $summary: expr, $long_help: expr, $display_usage: expr) => { uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText { - name: executable!(), + name: util_name!(), version: env!("CARGO_PKG_VERSION"), syntax: $syntax, summary: $summary, From 69ce4dc8e5236b45807116953e4c429c8632dd5a Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 28 Jul 2021 16:18:42 -0500 Subject: [PATCH 11/25] refactor/uucore ~ align return values for executable/util macros --- src/uucore/src/lib/macros.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 06aad6f36..931777220 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -20,7 +20,7 @@ macro_rules! executable( let exe = match $crate::executable_os!().to_str() { // * UTF-8 Some(s) => s.to_string(), - // * "lossless" debug format if `executable_os!()` is not well-formed UTF-8 + // * "lossless" debug format (if/when `executable_os!()` is not well-formed UTF-8) None => format!("{:?}", $crate::executable_os!()) }; &exe.to_owned() @@ -31,7 +31,14 @@ macro_rules! executable( #[macro_export] macro_rules! executable_name( () => ({ - &std::path::Path::new($crate::executable_os!()).file_stem().unwrap().to_string_lossy() + let stem = &std::path::Path::new($crate::executable_os!()).file_stem().unwrap().to_owned(); + let exe = match stem.to_str() { + // * UTF-8 + Some(s) => s.to_string(), + // * "lossless" debug format (if/when `executable_os!()` is not well-formed UTF-8) + None => format!("{:?}", stem) + }; + &exe.to_owned() }) ); @@ -40,11 +47,12 @@ macro_rules! executable_name( macro_rules! util_name( () => ({ let crate_name = env!("CARGO_PKG_NAME"); - if crate_name.starts_with("uu_") { + let name = if crate_name.starts_with("uu_") { &crate_name[3..] } else { - &crate_name - } + crate_name + }; + &name.to_owned() }) ); From f56fc5bf444f40a0b48101c157574635fccd1bf7 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 28 Jul 2021 16:20:30 -0500 Subject: [PATCH 12/25] refactor/uucore ~ use uucore args for executable macros --- src/uucore/src/lib/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 931777220..6d74ee260 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -9,7 +9,7 @@ #[macro_export] macro_rules! executable_os( () => ({ - &std::env::args_os().next().unwrap() + &uucore::args_os().next().unwrap() }) ); From 318f366ace28c496f89496ddf4ea7668d02cacd9 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Wed, 28 Jul 2021 16:22:02 -0500 Subject: [PATCH 13/25] change/uucore ~ add `execution_phrase!()` macro for use with usage messages --- src/uucore/src/lib/macros.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 6d74ee260..36336a24d 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -58,6 +58,23 @@ macro_rules! util_name( //==== +/// Derive the complete execution phrase for "usage". +#[macro_export] +macro_rules! execution_phrase( + () => ({ + let exe = if (executable_name!() == util_name!()) { + executable!().to_string() + } else { + format!("{} {}", executable!(), util_name!()) + .as_str() + .to_owned() + }; + &exe.to_owned() + }) +); + +//==== + #[macro_export] macro_rules! show( ($err:expr) => ({ From c0854000d169c386f59acf9f350d622a6cc96c5f Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Mon, 26 Jul 2021 22:54:48 -0500 Subject: [PATCH 14/25] refactor ~ use `execution_phrase!()` for usage messaging --- src/uu/base32/src/base32.rs | 6 +++--- src/uu/base64/src/base64.rs | 4 ++-- src/uu/basename/src/basename.rs | 6 +++--- src/uu/chgrp/src/chgrp.rs | 2 +- src/uu/chmod/src/chmod.rs | 2 +- src/uu/chown/src/chown.rs | 2 +- src/uu/chroot/src/chroot.rs | 5 ++--- src/uu/comm/src/comm.rs | 2 +- src/uu/cp/src/cp.rs | 6 +++--- src/uu/csplit/src/csplit.rs | 2 +- src/uu/df/src/df.rs | 4 ++-- src/uu/dircolors/src/dircolors.rs | 2 +- src/uu/dirname/src/dirname.rs | 2 +- src/uu/du/src/du.rs | 4 ++-- src/uu/expand/src/expand.rs | 2 +- src/uu/expr/src/expr.rs | 2 +- src/uu/fmt/src/fmt.rs | 2 +- src/uu/groups/src/groups.rs | 2 +- src/uu/hostname/src/hostname.rs | 2 +- src/uu/id/src/id.rs | 2 +- src/uu/install/src/install.rs | 4 ++-- src/uu/kill/src/kill.rs | 2 +- src/uu/link/src/link.rs | 2 +- src/uu/ln/src/ln.rs | 6 +++--- src/uu/logname/src/logname.rs | 2 +- src/uu/ls/src/ls.rs | 2 +- src/uu/mkdir/src/mkdir.rs | 4 ++-- src/uu/mknod/src/mknod.rs | 8 ++++---- src/uu/mktemp/src/mktemp.rs | 2 +- src/uu/mv/src/mv.rs | 6 +++--- src/uu/nice/src/nice.rs | 4 ++-- src/uu/nohup/src/nohup.rs | 2 +- src/uu/nproc/src/nproc.rs | 2 +- src/uu/numfmt/src/numfmt.rs | 2 +- src/uu/od/src/multifilereader.rs | 13 ++----------- src/uu/pathchk/src/pathchk.rs | 5 ++--- src/uu/pinky/src/pinky.rs | 2 +- src/uu/printenv/src/printenv.rs | 2 +- src/uu/printf/src/printf.rs | 8 ++++---- src/uu/pwd/src/pwd.rs | 2 +- src/uu/readlink/src/readlink.rs | 24 ++++++++++++++++++------ src/uu/realpath/src/realpath.rs | 2 +- src/uu/relpath/src/relpath.rs | 2 +- src/uu/rm/src/rm.rs | 4 ++-- src/uu/rmdir/src/rmdir.rs | 2 +- src/uu/seq/src/seq.rs | 8 ++++---- src/uu/shred/src/shred.rs | 2 +- src/uu/sleep/src/sleep.rs | 2 +- src/uu/sort/src/sort.rs | 3 +-- src/uu/split/src/split.rs | 4 +--- src/uu/stat/src/stat.rs | 2 +- src/uu/stdbuf/src/stdbuf.rs | 4 ++-- src/uu/sync/src/sync.rs | 2 +- src/uu/tee/src/tee.rs | 2 +- src/uu/timeout/src/timeout.rs | 2 +- src/uu/touch/src/touch.rs | 2 +- src/uu/tr/src/tr.rs | 6 +++--- src/uu/truncate/src/truncate.rs | 2 +- src/uu/tty/src/tty.rs | 2 +- src/uu/uname/src/uname.rs | 2 +- src/uu/uniq/src/uniq.rs | 2 +- src/uu/unlink/src/unlink.rs | 6 +++--- src/uu/uptime/src/uptime.rs | 2 +- src/uu/users/src/users.rs | 2 +- src/uu/wc/src/wc.rs | 2 +- src/uu/who/src/who.rs | 2 +- src/uucore/src/lib/macros.rs | 2 +- src/uucore_procs/src/lib.rs | 2 +- 68 files changed, 119 insertions(+), 121 deletions(-) diff --git a/src/uu/base32/src/base32.rs b/src/uu/base32/src/base32.rs index 8e02f03e0..a93b4e18b 100644 --- a/src/uu/base32/src/base32.rs +++ b/src/uu/base32/src/base32.rs @@ -29,13 +29,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); static BASE_CMD_PARSE_ERROR: i32 = 1; fn usage() -> String { - format!("{0} [OPTION]... [FILE]", executable!()) + format!("{0} [OPTION]... [FILE]", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { let format = Format::Base32; let usage = usage(); - let name = executable!(); + let name = util_name!(); let config_result: Result = base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage); @@ -59,5 +59,5 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - base_common::base_app(executable!(), VERSION, ABOUT) + base_common::base_app(util_name!(), VERSION, ABOUT) } diff --git a/src/uu/base64/src/base64.rs b/src/uu/base64/src/base64.rs index 48aee537d..b53ec32e9 100644 --- a/src/uu/base64/src/base64.rs +++ b/src/uu/base64/src/base64.rs @@ -30,13 +30,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); static BASE_CMD_PARSE_ERROR: i32 = 1; fn usage() -> String { - format!("{0} [OPTION]... [FILE]", executable!()) + format!("{0} [OPTION]... [FILE]", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { let format = Format::Base64; let usage = usage(); - let name = executable!(); + let name = util_name!(); let config_result: Result = base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage); let config = config_result.unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s)); diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index f3c9f5391..8de55af80 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -21,7 +21,7 @@ fn usage() -> String { format!( "{0} NAME [SUFFIX] {0} OPTION... NAME...", - executable!() + execution_phrase!() ) } @@ -47,7 +47,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "{1}\nTry `{0} --help` for more information.", - executable!(), + execution_phrase!(), "missing operand" ); } @@ -61,7 +61,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "extra operand '{1}'\nTry `{0} --help` for more information.", - executable!(), + execution_phrase!(), matches.values_of(options::NAME).unwrap().nth(2).unwrap() ); } diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index 11a45c90a..5dbcc277e 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -62,7 +62,7 @@ const FTS_LOGICAL: u8 = 1 << 2; fn usage() -> String { format!( "{0} [OPTION]... GROUP FILE...\n {0} [OPTION]... --reference=RFILE FILE...", - executable!() + execution_phrase!() ) } diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index e1d8b32e4..88ad22969 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -41,7 +41,7 @@ fn usage() -> String { "{0} [OPTION]... MODE[,MODE]... FILE... or: {0} [OPTION]... OCTAL-MODE FILE... or: {0} [OPTION]... --reference=RFILE FILE...", - executable!() + execution_phrase!() ) } diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index a5d7c5ac7..a7824f248 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -64,7 +64,7 @@ const FTS_LOGICAL: u8 = 1 << 2; fn usage() -> String { format!( "{0} [OPTION]... [OWNER][:[GROUP]] FILE...\n{0} [OPTION]... --reference=RFILE FILE...", - executable!() + execution_phrase!() ) } diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 01a7c6b84..b622b51a1 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -16,9 +16,8 @@ use std::io::Error; use std::path::Path; use std::process::Command; use uucore::libc::{self, chroot, setgid, setgroups, setuid}; -use uucore::{entries, InvalidEncodingHandling}; +use uucore::{entries, execution_phrase, InvalidEncodingHandling}; -static NAME: &str = "chroot"; static ABOUT: &str = "Run COMMAND with root directory set to NEWROOT."; static SYNTAX: &str = "[OPTION]... NEWROOT [COMMAND [ARG]...]"; @@ -47,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { None => crash!( 1, "Missing operand: NEWROOT\nTry `{} --help` for more information.", - NAME + execution_phrase!() ), }; diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index 36238cd5f..02c5598be 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -32,7 +32,7 @@ mod options { } fn usage() -> String { - format!("{} [OPTION]... FILE1 FILE2", executable!()) + format!("{} [OPTION]... FILE1 FILE2", execution_phrase!()) } fn mkdelim(col: usize, opts: &ArgMatches) -> String { diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 406f6757d..086b734e8 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 `{} --help` for more information.", description, executable!()) } + Backup(description: String) { display("{}\nTry `{} --help` for more information.", description, execution_phrase!()) } } } @@ -223,7 +223,7 @@ fn usage() -> String { "{0} [OPTION]... [-T] SOURCE DEST {0} [OPTION]... SOURCE... DIRECTORY {0} [OPTION]... -t DIRECTORY SOURCE...", - executable!() + execution_phrase!() ) } @@ -1060,7 +1060,7 @@ impl OverwriteMode { match *self { OverwriteMode::NoClobber => Err(Error::NotAllFilesCopied), OverwriteMode::Interactive(_) => { - if prompt_yes!("{}: overwrite {}? ", executable!(), path.display()) { + if prompt_yes!("{}: overwrite {}? ", util_name!(), path.display()) { Ok(()) } else { Err(Error::Skipped(format!( diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 409b17b98..c89d06cf3 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -35,7 +35,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]... FILE PATTERN...", executable!()) + format!("{0} [OPTION]... FILE PATTERN...", execution_phrase!()) } /// Command line options for csplit. diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 4ffa8b532..52fae4702 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -80,7 +80,7 @@ struct Filesystem { } fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", executable!()) + format!("{0} [OPTION]... [FILE]...", execution_phrase!()) } impl FsSelector { @@ -295,7 +295,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { #[cfg(windows)] { if matches.is_present(OPT_INODES) { - println!("{}: doesn't support -i option", executable!()); + println!("{}: doesn't support -i option", util_name!()); return Ok(()); } } diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 90b48c301..c70fd97ee 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -63,7 +63,7 @@ pub fn guess_syntax() -> OutputFmt { } fn usage() -> String { - format!("{0} {1}", executable!(), SYNTAX) + format!("{0} {1}", execution_phrase!(), SYNTAX) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 3162bef48..4600d67ac 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -21,7 +21,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION] NAME...", executable!()) + format!("{0} [OPTION] NAME...", execution_phrase!()) } fn get_long_usage() -> String { diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 56f412ffb..2c430d693 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -396,7 +396,7 @@ fn usage() -> String { format!( "{0} [OPTION]... [FILE]... {0} [OPTION]... --files0-from=F", - executable!() + execution_phrase!() ) } @@ -424,7 +424,7 @@ Valid arguments are: - 'iso' Try `{} --help` for more information.", s, - executable!() + execution_phrase!() ), DuError::InvalidTimeArg(s) => write!( f, diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 29de6ae44..0cd4b2719 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -33,7 +33,7 @@ static LONG_HELP: &str = ""; static DEFAULT_TABSTOP: usize = 8; fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", executable!()) + format!("{0} [OPTION]... [FILE]...", execution_phrase!()) } /// The mode to use when replacing tabs beyond the last one specified in diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index b37e1ced6..0a9d76f67 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -140,5 +140,5 @@ Environment variables: } fn print_version() { - println!("{} {}", executable!(), crate_version!()); + println!("{} {}", util_name!(), crate_version!()); } diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index 80f74cf84..d42151503 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -51,7 +51,7 @@ static OPT_TAB_WIDTH: &str = "tab-width"; static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{} [OPTION]... [FILE]...", executable!()) + format!("{} [OPTION]... [FILE]...", execution_phrase!()) } pub type FileOrStdReader = BufReader>; diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index fe1065cc1..83be0932b 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -29,7 +29,7 @@ static ABOUT: &str = "Print group memberships for each USERNAME or, \ (which may differ if the groups data‐base has changed)."; fn usage() -> String { - format!("{0} [OPTION]... [USERNAME]...", executable!()) + format!("{0} [OPTION]... [USERNAME]...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index 2b7deb565..2dc68abfb 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } fn usage() -> String { - format!("{0} [OPTION]... [HOSTNAME]", executable!()) + format!("{0} [OPTION]... [HOSTNAME]", execution_phrase!()) } fn execute(args: impl uucore::Args) -> UResult<()> { diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 16c521ea3..74523213e 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -77,7 +77,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]... [USER]...", executable!()) + format!("{0} [OPTION]... [USER]...", execution_phrase!()) } fn get_description() -> String { diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 5ee103e0f..a1c6d4225 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -89,7 +89,7 @@ impl Display for InstallError { IE::DirNeedsArg() => write!( f, "{} with -d requires at least one argument.", - executable!() + util_name!() ), IE::CreateDirFailed(dir, e) => { Display::fmt(&uio_error!(e, "failed to create {}", dir.display()), f) @@ -173,7 +173,7 @@ static OPT_CONTEXT: &str = "context"; static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", executable!()) + format!("{0} [OPTION]... [FILE]...", execution_phrase!()) } /// Main install utility function, called from main.rs. diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index e9ec70964..08dff87d4 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -41,7 +41,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .accept_any(); let (args, obs_signal) = handle_obsolete(args); - let usage = format!("{} [OPTIONS]... PID...", executable!()); + let usage = format!("{} [OPTIONS]... PID...", execution_phrase!()); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let mode = if matches.is_present(options::TABLE) || matches.is_present(options::TABLE_OLD) { diff --git a/src/uu/link/src/link.rs b/src/uu/link/src/link.rs index d06025815..03dd46aee 100644 --- a/src/uu/link/src/link.rs +++ b/src/uu/link/src/link.rs @@ -20,7 +20,7 @@ pub mod options { } fn usage() -> String { - format!("{0} FILE1 FILE2", executable!()) + format!("{0} FILE1 FILE2", execution_phrase!()) } pub fn normalize_error_message(e: Error) -> String { diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 572c68379..62748ae78 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -70,7 +70,7 @@ impl Display for LnError { f, "extra operand '{}'\nTry `{} --help` for more information.", s, - executable!() + execution_phrase!() ), Self::InvalidBackupMode(s) => write!(f, "{}", s), } @@ -98,7 +98,7 @@ fn usage() -> String { {0} [OPTION]... TARGET (2nd form) {0} [OPTION]... TARGET... DIRECTORY (3rd form) {0} [OPTION]... -t DIRECTORY TARGET... (4th form)", - executable!() + execution_phrase!() ) } @@ -431,7 +431,7 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> Result<()> { match settings.overwrite { OverwriteMode::NoClobber => {} OverwriteMode::Interactive => { - print!("{}: overwrite '{}'? ", executable!(), dst.display()); + print!("{}: overwrite '{}'? ", util_name!(), dst.display()); if !read_yes() { return Ok(()); } diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 095f3fc84..e9952ddef 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -36,7 +36,7 @@ fn get_userlogin() -> Option { static SUMMARY: &str = "Print user's login name"; fn usage() -> String { - String::from(executable!()) + execution_phrase!().to_string() } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index f02a53738..6ba3ec4f1 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -47,7 +47,7 @@ use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; use uucore::{fs::display_permissions, version_cmp::version_cmp}; fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", executable!()) + format!("{0} [OPTION]... [FILE]...", execution_phrase!()) } pub mod options { diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index e9aa4bc22..046628f3a 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -23,7 +23,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]... [USER]", executable!()) + format!("{0} [OPTION]... [USER]", execution_phrase!()) } #[uucore_procs::gen_uumain] @@ -103,7 +103,7 @@ fn mkdir(path: &Path, recursive: bool, mode: u16, verbose: bool) -> UResult<()> create_dir(path).map_err_context(|| format!("cannot create directory '{}'", path.display()))?; if verbose { - println!("{}: created directory '{}'", executable!(), path.display()); + println!("{}: created directory '{}'", util_name!(), path.display()); } chmod(path, mode) diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index bd26949cd..19c61bcfe 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -18,7 +18,6 @@ use libc::{S_IFBLK, S_IFCHR, S_IFIFO, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOT use uucore::InvalidEncodingHandling; -static NAME: &str = "mknod"; static ABOUT: &str = "Create the special file NAME of the given TYPE."; static USAGE: &str = "mknod [OPTION]... NAME TYPE [MAJOR MINOR]"; static LONG_HELP: &str = "Mandatory arguments to long options are mandatory for short options too. @@ -72,7 +71,8 @@ fn _mknod(file_name: &str, mode: mode_t, dev: dev_t) -> i32 { } if errno == -1 { - let c_str = CString::new(NAME).expect("Failed to convert to CString"); + let c_str = + CString::new(execution_phrase!().as_bytes()).expect("Failed to convert to CString"); // shows the error from the mknod syscall libc::perror(c_str.as_ptr()); } @@ -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.", execution_phrase!()); 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.", execution_phrase!()); 1 } (Some(major), Some(minor)) => { diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 52d60d140..2d42d38ba 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -37,7 +37,7 @@ static OPT_T: &str = "t"; static ARG_TEMPLATE: &str = "template"; fn usage() -> String { - format!("{0} [OPTION]... [TEMPLATE]", executable!()) + format!("{0} [OPTION]... [TEMPLATE]", execution_phrase!()) } #[derive(Debug)] diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 1c25e653c..ecd57ee5a 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -63,7 +63,7 @@ fn usage() -> String { "{0} [OPTION]... [-T] SOURCE DEST {0} [OPTION]... SOURCE... DIRECTORY {0} [OPTION]... -t DIRECTORY SOURCE...", - executable!() + execution_phrase!() ) } @@ -296,7 +296,7 @@ fn exec(files: &[PathBuf], b: Behavior) -> i32 { "mv: extra operand '{}'\n\ Try `{} --help` for more information.", files[2].display(), - executable!() + execution_phrase!() ); return 1; } @@ -353,7 +353,7 @@ fn rename(from: &Path, to: &Path, b: &Behavior) -> io::Result<()> { match b.overwrite { OverwriteMode::NoClobber => return Ok(()), OverwriteMode::Interactive => { - println!("{}: overwrite '{}'? ", executable!(), to.display()); + println!("{}: overwrite '{}'? ", util_name!(), to.display()); if !read_yes() { return Ok(()); } diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index c071a875f..835034b74 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -31,7 +31,7 @@ Run COMMAND with an adjusted niceness, which affects process scheduling. With no COMMAND, print the current niceness. Niceness values range from at least -20 (most favorable to the process) to 19 (least favorable to the process).", - executable!() + execution_phrase!() ) } @@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if !matches.is_present(options::COMMAND) { show_error!( "A command must be given with an adjustment.\nTry `{} --help` for more information.", - executable!() + execution_phrase!() ); return 125; } diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index a6f08e806..17b06301f 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -157,7 +157,7 @@ fn find_stdout() -> File { } fn usage() -> String { - format!("{0} COMMAND [ARG]...\n {0} FLAG", executable!()) + format!("{0} COMMAND [ARG]...\n {0} FLAG", execution_phrase!()) } #[cfg(target_vendor = "apple")] diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index 427a3cd2f..c10d79d40 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -28,7 +28,7 @@ static OPT_IGNORE: &str = "ignore"; static ABOUT: &str = "Print the number of cores available to the current process."; fn usage() -> String { - format!("{0} [OPTIONS]...", executable!()) + format!("{0} [OPTIONS]...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 6012bbf82..849abeb71 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -51,7 +51,7 @@ Multiple fields/ranges can be separated with commas "; fn usage() -> String { - format!("{0} [OPTION]... [NUMBER]...", executable!()) + format!("{0} [OPTION]... [NUMBER]...", execution_phrase!()) } fn handle_args<'a>(args: impl Iterator, options: NumfmtOptions) -> Result<()> { diff --git a/src/uu/od/src/multifilereader.rs b/src/uu/od/src/multifilereader.rs index 1255da66d..303093b01 100644 --- a/src/uu/od/src/multifilereader.rs +++ b/src/uu/od/src/multifilereader.rs @@ -57,12 +57,7 @@ impl<'b> MultifileReader<'b> { // print an error at the time that the file is needed, // then move on the the next file. // This matches the behavior of the original `od` - eprintln!( - "{}: '{}': {}", - executable!().split("::").next().unwrap(), // remove module - fname, - e - ); + eprintln!("{}: '{}': {}", util_name!(), fname, e); self.any_err = true } } @@ -95,11 +90,7 @@ impl<'b> io::Read for MultifileReader<'b> { Ok(0) => break, Ok(n) => n, Err(e) => { - eprintln!( - "{}: I/O: {}", - executable!().split("::").next().unwrap(), // remove module - e - ); + eprintln!("{}: I/O: {}", util_name!(), e); self.any_err = true; break; } diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 4d257a771..65c917ac0 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -25,7 +25,6 @@ enum Mode { Both, // a combination of `Basic` and `Extra` } -static NAME: &str = "pathchk"; static ABOUT: &str = "Check whether file names are valid or portable"; mod options { @@ -40,7 +39,7 @@ const POSIX_PATH_MAX: usize = 256; const POSIX_NAME_MAX: usize = 14; fn usage() -> String { - format!("{0} [OPTION]... NAME...", executable!()) + format!("{0} [OPTION]... NAME...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -71,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let mut res = if paths.is_none() { show_error!( "missing operand\nTry `{} --help` for more information", - NAME + execution_phrase!() ); false } else { diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 4aad2c07d..9268ffd2b 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -41,7 +41,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]... [USER]...", executable!()) + format!("{0} [OPTION]... [USER]...", execution_phrase!()) } fn get_long_usage() -> String { diff --git a/src/uu/printenv/src/printenv.rs b/src/uu/printenv/src/printenv.rs index 0e86f1012..da46f7667 100644 --- a/src/uu/printenv/src/printenv.rs +++ b/src/uu/printenv/src/printenv.rs @@ -20,7 +20,7 @@ static OPT_NULL: &str = "null"; static ARG_VARIABLES: &str = "variables"; fn usage() -> String { - format!("{0} [VARIABLE]... [OPTION]...", executable!()) + format!("{0} [VARIABLE]... [OPTION]...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index 211522fbf..26a1b29b2 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -281,11 +281,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); - let location = &args[0]; if args.len() <= 1 { println!( - "{0}: missing operand\nTry `{0} --help` for more information.", - location + "{0}: missing operand\nTry `{1} --help` for more information.", + util_name!(), + execution_phrase!() ); return 1; } @@ -294,7 +294,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if formatstr == "--help" { print!("{} {}", LONGHELP_LEAD, LONGHELP_BODY); } else if formatstr == "--version" { - println!("{} {}", executable!(), crate_version!()); + println!("{} {}", util_name!(), crate_version!()); } else { let printf_args = &args[2..]; memo::Memo::run_all(formatstr, printf_args); diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index bfdfafd13..388a10463 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -35,7 +35,7 @@ pub fn absolute_path(path: &Path) -> io::Result { } fn usage() -> String { - format!("{0} [OPTION]... FILE...", executable!()) + format!("{0} [OPTION]... FILE...", execution_phrase!()) } #[uucore_procs::gen_uumain] diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index b86dff162..cf788c1fe 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -16,7 +16,6 @@ use std::io::{stdout, Write}; use std::path::{Path, PathBuf}; use uucore::fs::{canonicalize, CanonicalizeMode}; -const NAME: &str = "readlink"; const ABOUT: &str = "Print value of a symbolic link or canonical file name."; const OPT_CANONICALIZE: &str = "canonicalize"; const OPT_CANONICALIZE_MISSING: &str = "canonicalize-missing"; @@ -30,7 +29,7 @@ const OPT_ZERO: &str = "zero"; const ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", executable!()) + format!("{0} [OPTION]... [FILE]...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -60,12 +59,15 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "missing operand\nTry `{} --help` for more information", - NAME + execution_phrase!() ); } if no_newline && files.len() > 1 && !silent { - eprintln!("{}: ignoring --no-newline with multiple arguments", NAME); + eprintln!( + "{}: ignoring --no-newline with multiple arguments", + util_name!() + ); no_newline = false; } @@ -76,7 +78,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 { Ok(path) => show(&path, no_newline, use_zero), Err(err) => { if verbose { - eprintln!("{}: {}: errno {}", NAME, f, err.raw_os_error().unwrap()); + eprintln!( + "{}: {}: errno {}", + util_name!(), + f, + err.raw_os_error().unwrap() + ); } return 1; } @@ -86,7 +93,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 { Ok(path) => show(&path, no_newline, use_zero), Err(err) => { if verbose { - eprintln!("{}: {}: errno {:?}", NAME, f, err.raw_os_error().unwrap()); + eprintln!( + "{}: {}: errno {:?}", + util_name!(), + f, + err.raw_os_error().unwrap() + ); } return 1; } diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index 494fe41dc..7ce8fc179 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -23,7 +23,7 @@ static OPT_ZERO: &str = "zero"; static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [OPTION]... FILE...", executable!()) + format!("{0} [OPTION]... FILE...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/relpath/src/relpath.rs b/src/uu/relpath/src/relpath.rs index b7fa8991c..941a6a3f2 100644 --- a/src/uu/relpath/src/relpath.rs +++ b/src/uu/relpath/src/relpath.rs @@ -26,7 +26,7 @@ mod options { } fn usage() -> String { - format!("{} [-d DIR] TO [FROM]", executable!()) + format!("{} [-d DIR] TO [FROM]", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 4b435807b..03977bc3e 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -53,7 +53,7 @@ static OPT_VERBOSE: &str = "verbose"; static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [OPTION]... FILE...", executable!()) + format!("{0} [OPTION]... FILE...", execution_phrase!()) } fn get_long_usage() -> String { @@ -93,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { // Still check by hand and not use clap // Because "rm -f" is a thing show_error!("missing an argument"); - show_error!("for help, try '{0} --help'", executable!()); + show_error!("for help, try '{0} --help'", execution_phrase!()); return 1; } else { let options = Options { diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index 880300a7a..135350a8e 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -27,7 +27,7 @@ static ENOTDIR: i32 = 20; static ENOTDIR: i32 = 267; fn usage() -> String { - format!("{0} [OPTION]... DIRECTORY...", executable!()) + format!("{0} [OPTION]... DIRECTORY...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 2042cf23f..f3e57881e 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -27,7 +27,7 @@ fn usage() -> String { "{0} [OPTION]... LAST {0} [OPTION]... FIRST LAST {0} [OPTION]... FIRST INCREMENT LAST", - executable!() + execution_phrase!() ) } #[derive(Clone)] @@ -72,13 +72,13 @@ impl FromStr for Number { Ok(value) if value.is_nan() => Err(format!( "invalid 'not-a-number' argument: '{}'\nTry `{} --help` for more information.", s, - executable!(), + execution_phrase!(), )), Ok(value) => Ok(Number::F64(value)), Err(_) => Err(format!( "invalid floating point argument: '{}'\nTry `{} --help` for more information.", s, - executable!(), + execution_phrase!(), )), }, } @@ -123,7 +123,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { show_error!( "invalid Zero increment value: '{}'\nTry `{} --help` for more information.", numbers[1], - executable!() + execution_phrase!() ); return 1; } diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 936577f01..521cb8dc6 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -214,7 +214,7 @@ for even very expensive hardware probing to recover the data. "; fn usage() -> String { - format!("{} [OPTION]... FILE...", executable!()) + format!("{} [OPTION]... FILE...", execution_phrase!()) } static AFTER_HELP: &str = diff --git a/src/uu/sleep/src/sleep.rs b/src/uu/sleep/src/sleep.rs index 624e65901..136d92e4d 100644 --- a/src/uu/sleep/src/sleep.rs +++ b/src/uu/sleep/src/sleep.rs @@ -29,7 +29,7 @@ mod options { fn usage() -> String { format!( "{0} {1}[SUFFIX]... \n {0} OPTION", - executable!(), + execution_phrase!(), options::NUMBER ) } diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 78b6f8b64..049be5352 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -52,7 +52,6 @@ use uucore::InvalidEncodingHandling; use crate::tmp_dir::TmpDirWrapper; -const NAME: &str = "sort"; const ABOUT: &str = "Display sorted concatenation of all FILE(s)."; const LONG_HELP_KEYS: &str = "The key format is FIELD[.CHAR][OPTIONS][,FIELD[.CHAR]][OPTIONS]. @@ -1061,7 +1060,7 @@ fn usage() -> String { Write the sorted concatenation of all FILE(s) to standard output. Mandatory arguments for long options are mandatory for short options too. With no FILE, or when FILE is -, read standard input.", - NAME + execution_phrase!() ) } diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index bc38818b9..ce21361af 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -21,8 +21,6 @@ use std::path::Path; use std::{char, fs::remove_file}; use uucore::parse_size::parse_size; -static NAME: &str = "split"; - static OPT_BYTES: &str = "bytes"; static OPT_LINE_BYTES: &str = "line-bytes"; static OPT_LINES: &str = "lines"; @@ -37,7 +35,7 @@ static ARG_INPUT: &str = "input"; static ARG_PREFIX: &str = "prefix"; fn usage() -> String { - format!("{0} [OPTION]... [INPUT [PREFIX]]", NAME) + format!("{0} [OPTION]... [INPUT [PREFIX]]", execution_phrase!()) } fn get_long_usage() -> String { format!( diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 4a12e4fb7..d3783d725 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -883,7 +883,7 @@ impl Stater { } fn usage() -> String { - format!("{0} [OPTION]... FILE...", executable!()) + format!("{0} [OPTION]... FILE...", execution_phrase!()) } fn get_long_usage() -> String { diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index bac5040cf..87e478b73 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -48,7 +48,7 @@ mod options { } fn usage() -> String { - format!("{0} OPTION... COMMAND", executable!()) + format!("{0} OPTION... COMMAND", execution_phrase!()) } const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.so")); @@ -161,7 +161,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { 125, "{}\nTry `{} --help` for more information.", e.0, - executable!() + execution_phrase!() ) }); diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 123167db7..7dd37d780 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -160,7 +160,7 @@ mod platform { } fn usage() -> String { - format!("{0} [OPTION]... FILE...", executable!()) + format!("{0} [OPTION]... FILE...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 2f1b17ebe..461600003 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -33,7 +33,7 @@ struct Options { } fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", executable!()) + format!("{0} [OPTION]... [FILE]...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index e0fbe8a54..8b169b5b5 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -23,7 +23,7 @@ use uucore::InvalidEncodingHandling; static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION."; fn usage() -> String { - format!("{0} [OPTION] DURATION COMMAND...", executable!()) + format!("{0} [OPTION] DURATION COMMAND...", execution_phrase!()) } const ERR_EXIT_STATUS: i32 = 125; diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index bdb65683f..8ddfcfa74 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -48,7 +48,7 @@ fn local_tm_to_filetime(tm: time::Tm) -> FileTime { } fn usage() -> String { - format!("{0} [OPTION]... [USER]", executable!()) + format!("{0} [OPTION]... [USER]", execution_phrase!()) } #[uucore_procs::gen_uumain] diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index ddb866393..0a277d663 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -229,7 +229,7 @@ fn translate_input( } fn usage() -> String { - format!("{} [OPTION]... SET1 [SET2]", executable!()) + format!("{} [OPTION]... SET1 [SET2]", execution_phrase!()) } fn get_long_usage() -> String { @@ -264,7 +264,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if sets.is_empty() { show_error!( "missing operand\nTry `{} --help` for more information.", - executable!() + execution_phrase!() ); return 1; } @@ -273,7 +273,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { show_error!( "missing operand after '{}'\nTry `{} --help` for more information.", sets[0], - executable!() + execution_phrase!() ); return 1; } diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index c5f9fb5b7..fdcff3fd5 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -64,7 +64,7 @@ pub mod options { } fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", executable!()) + format!("{0} [OPTION]... [FILE]...", execution_phrase!()) } fn get_long_usage() -> String { diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index df6c43a27..284916050 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -24,7 +24,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]...", executable!()) + format!("{0} [OPTION]...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index 2b16c85ec..b15d950bf 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -50,7 +50,7 @@ const HOST_OS: &str = "Fuchsia"; const HOST_OS: &str = "Redox"; pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = format!("{} [OPTION]...", executable!()); + let usage = format!("{} [OPTION]...", execution_phrase!()); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let uname = return_if_err!(1, PlatformInfo::new()); diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index fd8b4019b..10cb7a4ce 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -222,7 +222,7 @@ fn opt_parsed(opt_name: &str, matches: &ArgMatches) -> Option { } fn usage() -> String { - format!("{0} [OPTION]... [INPUT [OUTPUT]]...", executable!()) + format!("{0} [OPTION]... [INPUT [OUTPUT]]...", execution_phrase!()) } fn get_long_usage() -> String { diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index 0601b3e54..182729fd4 100644 --- a/src/uu/unlink/src/unlink.rs +++ b/src/uu/unlink/src/unlink.rs @@ -23,7 +23,7 @@ static ABOUT: &str = "Unlink the file at [FILE]."; static OPT_PATH: &str = "FILE"; fn usage() -> String { - format!("{} [OPTION]... FILE", executable!()) + format!("{} [OPTION]... FILE", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -44,13 +44,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "missing operand\nTry `{0} --help` for more information.", - executable!() + execution_phrase!() ); } else if paths.len() > 1 { crash!( 1, "extra operand: '{1}'\nTry `{0} --help` for more information.", - executable!(), + execution_phrase!(), paths[1] ); } diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index 33f3ec965..b19566ec3 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -33,7 +33,7 @@ extern "C" { } fn usage() -> String { - format!("{0} [OPTION]...", executable!()) + format!("{0} [OPTION]...", execution_phrase!()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index 3f081f891..7aed00507 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -19,7 +19,7 @@ static ABOUT: &str = "Print the user names of users currently logged in to the c static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [FILE]", executable!()) + format!("{0} [FILE]", execution_phrase!()) } fn get_long_usage() -> String { diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index e21eb0b7e..3077d31d9 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -99,7 +99,7 @@ fn usage() -> String { format!( "{0} [OPTION]... [FILE]... With no FILE, or when FILE is -, read standard input.", - executable!() + execution_phrase!() ) } diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 558d42f1b..59e8b7c36 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -45,7 +45,7 @@ static RUNLEVEL_HELP: &str = "print current runlevel"; static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)"; fn usage() -> String { - format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", executable!()) + format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", execution_phrase!()) } fn get_long_usage() -> String { diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 36336a24d..df3834f7e 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -125,7 +125,7 @@ macro_rules! show_usage_error( ($($args:tt)+) => ({ eprint!("{}: ", $crate::util_name!()); eprintln!($($args)+); - eprintln!("Try `{:?} --help` for more information.", $crate::executable!()); + eprintln!("Try `{} --help` for more information.", $crate::execution_phrase!()); }) ); diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index 2467ce2c7..74ac60220 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.", execution_phrase!()); } e.code() } From 4da46d93c7bb8269eaa28fad2cb09aeecc255c5e Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Tue, 27 Jul 2021 00:21:12 -0500 Subject: [PATCH 15/25] tests ~ fix tests for new `execution_phrase!()` and usage phrasing --- tests/by-util/test_base32.rs | 14 +++++++++----- tests/by-util/test_basename.rs | 19 ++++++++++++------- tests/by-util/test_cp.rs | 13 ++++++++----- tests/by-util/test_more.rs | 12 ++++++++---- tests/by-util/test_mv.rs | 9 ++++++--- tests/by-util/test_nice.rs | 9 +++++++-- tests/by-util/test_rm.rs | 10 ++++++---- tests/by-util/test_seq.rs | 20 ++++++++++++++------ tests/by-util/test_stdbuf.rs | 23 +++++++++++++++++------ tests/by-util/test_unlink.rs | 13 ++++++++----- tests/common/util.rs | 2 +- 11 files changed, 96 insertions(+), 48 deletions(-) diff --git a/tests/by-util/test_base32.rs b/tests/by-util/test_base32.rs index 178341f44..5c74c5b59 100644 --- a/tests/by-util/test_base32.rs +++ b/tests/by-util/test_base32.rs @@ -85,11 +85,15 @@ fn test_wrap() { #[test] fn test_wrap_no_arg() { for wrap_param in &["-w", "--wrap"] { - let expected_stderr = "error: The argument '--wrap \' requires a value but none was \ - supplied\n\nUSAGE:\n base32 [OPTION]... [FILE]\n\nFor more \ - information try --help" - .to_string(); - new_ucmd!() + let ts = TestScenario::new(util_name!()); + let expected_stderr = &format!( + "error: The argument '--wrap \' requires a value but none was \ + supplied\n\nUSAGE:\n {1} {0} [OPTION]... [FILE]\n\nFor more \ + information try --help", + ts.util_name, + ts.bin_path.to_string_lossy() + ); + ts.ucmd() .arg(wrap_param) .fails() .stderr_only(expected_stderr); diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index d9632106e..9701e9973 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -114,9 +114,12 @@ fn test_no_args() { #[test] fn test_no_args_output() { - new_ucmd!() - .fails() - .stderr_is("basename: missing operand\nTry 'basename --help' for more information."); + let ts = TestScenario::new(util_name!()); + ts.ucmd().fails().stderr_is(&format!( + "{0}: missing operand\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] @@ -126,10 +129,12 @@ fn test_too_many_args() { #[test] fn test_too_many_args_output() { - new_ucmd!() - .args(&["a", "b", "c"]) - .fails() - .stderr_is("basename: extra operand 'c'\nTry 'basename --help' for more information."); + let ts = TestScenario::new(util_name!()); + ts.ucmd().args(&["a", "b", "c"]).fails().stderr_is(format!( + "{0}: extra operand 'c'\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[cfg(any(unix, target_os = "redox"))] diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 541e6b5d9..6d739f448 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -561,14 +561,17 @@ fn test_cp_backup_off() { #[test] fn test_cp_backup_no_clobber_conflicting_options() { - let (_, mut ucmd) = at_and_ucmd!(); - - ucmd.arg("--backup") + let ts = TestScenario::new(util_name!()); + ts.ucmd() + .arg("--backup") .arg("--no-clobber") .arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE) - .fails() - .stderr_is("cp: options --backup and --no-clobber are mutually exclusive\nTry 'cp --help' for more information."); + .fails().stderr_is(&format!( + "{0}: options --backup and --no-clobber are mutually exclusive\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/by-util/test_more.rs b/tests/by-util/test_more.rs index 9b28ee24e..a422b23a5 100644 --- a/tests/by-util/test_more.rs +++ b/tests/by-util/test_more.rs @@ -15,11 +15,15 @@ fn test_more_dir_arg() { // Maybe we could capture the error, i.e. "Device not found" in that case // but I am leaving this for later if atty::is(atty::Stream::Stdout) { - let result = new_ucmd!().arg(".").run(); + let ts = TestScenario::new(util_name!()); + let result = ts.ucmd().arg(".").run(); result.failure(); - const EXPECTED_ERROR_MESSAGE: &str = - "more: '.' is a directory.\nTry 'more --help' for more information."; - assert_eq!(result.stderr_str().trim(), EXPECTED_ERROR_MESSAGE); + let expected_error_message = &format!( + "{0}: '.' is a directory.\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + ); + assert_eq!(result.stderr_str().trim(), expected_error_message); } else { } } diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 02c65f68d..8596f8477 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -522,14 +522,17 @@ fn test_mv_backup_off() { #[test] fn test_mv_backup_no_clobber_conflicting_options() { - let (_, mut ucmd) = at_and_ucmd!(); + let ts = TestScenario::new(util_name!()); - ucmd.arg("--backup") + ts.ucmd().arg("--backup") .arg("--no-clobber") .arg("file1") .arg("file2") .fails() - .stderr_is("mv: options --backup and --no-clobber are mutually exclusive\nTry 'mv --help' for more information."); + .stderr_is(&format!("{0}: options --backup and --no-clobber are mutually exclusive\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/by-util/test_nice.rs b/tests/by-util/test_nice.rs index 25886de78..639fa5697 100644 --- a/tests/by-util/test_nice.rs +++ b/tests/by-util/test_nice.rs @@ -22,10 +22,15 @@ fn test_negative_adjustment() { #[test] fn test_adjustment_with_no_command_should_error() { - new_ucmd!() + let ts = TestScenario::new(util_name!()); + + ts.ucmd() .args(&["-n", "19"]) .run() - .stderr_is("nice: A command must be given with an adjustment.\nTry \"nice --help\" for more information.\n"); + .stderr_is(&format!("{0}: A command must be given with an adjustment.\nTry `{1} {0} --help` for more information.\n", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 0592be244..32bc43837 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -255,10 +255,12 @@ fn test_rm_force_no_operand() { #[test] fn test_rm_no_operand() { - let mut ucmd = new_ucmd!(); - - ucmd.fails() - .stderr_is("rm: missing an argument\nrm: for help, try 'rm --help'\n"); + let ts = TestScenario::new(util_name!()); + ts.ucmd().fails().stderr_is(&format!( + "{0}: missing an argument\n{0}: for help, try '{1} {0} --help'\n", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index be04bf1fd..cc94d4b1f 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -2,16 +2,24 @@ use crate::common::util::*; #[test] fn test_rejects_nan() { - new_ucmd!().args(&["NaN"]).fails().stderr_only( - "seq: invalid 'not-a-number' argument: 'NaN'\nTry 'seq --help' for more information.", - ); + let ts = TestScenario::new(util_name!()); + + ts.ucmd().args(&["NaN"]).fails().stderr_only(format!( + "{0}: invalid 'not-a-number' argument: 'NaN'\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] fn test_rejects_non_floats() { - new_ucmd!().args(&["foo"]).fails().stderr_only( - "seq: invalid floating point argument: 'foo'\nTry 'seq --help' for more information.", - ); + let ts = TestScenario::new(util_name!()); + + ts.ucmd().args(&["foo"]).fails().stderr_only(&format!( + "{0}: invalid floating point argument: 'foo'\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } // ---- Tests for the big integer based path ---- diff --git a/tests/by-util/test_stdbuf.rs b/tests/by-util/test_stdbuf.rs index 66892ea0f..d705c0854 100644 --- a/tests/by-util/test_stdbuf.rs +++ b/tests/by-util/test_stdbuf.rs @@ -25,15 +25,19 @@ fn test_stdbuf_line_buffered_stdout() { #[cfg(not(target_os = "windows"))] #[test] fn test_stdbuf_no_buffer_option_fails() { - new_ucmd!().args(&["head"]).fails().stderr_is( + let ts = TestScenario::new(util_name!()); + + ts.ucmd().args(&["head"]).fails().stderr_is(&format!( "error: The following required arguments were not provided:\n \ --error \n \ --input \n \ --output \n\n\ USAGE:\n \ - stdbuf OPTION... COMMAND\n\n\ + {1} {0} OPTION... COMMAND\n\n\ For more information try --help", - ); + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[cfg(not(target_os = "windows"))] @@ -49,9 +53,16 @@ fn test_stdbuf_trailing_var_arg() { #[cfg(not(target_os = "windows"))] #[test] fn test_stdbuf_line_buffering_stdin_fails() { - new_ucmd!().args(&["-i", "L", "head"]).fails().stderr_is( - "stdbuf: line buffering stdin is meaningless\nTry 'stdbuf --help' for more information.", - ); + let ts = TestScenario::new(util_name!()); + + ts.ucmd() + .args(&["-i", "L", "head"]) + .fails() + .stderr_is(&format!( + "{0}: line buffering stdin is meaningless\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[cfg(not(target_os = "windows"))] diff --git a/tests/by-util/test_unlink.rs b/tests/by-util/test_unlink.rs index 1999e965c..0c82b6a39 100644 --- a/tests/by-util/test_unlink.rs +++ b/tests/by-util/test_unlink.rs @@ -14,17 +14,20 @@ fn test_unlink_file() { #[test] fn test_unlink_multiple_files() { - let (at, mut ucmd) = at_and_ucmd!(); + let ts = TestScenario::new(util_name!()); + + let (at, mut ucmd) = (ts.fixtures.clone(), ts.ucmd()); let file_a = "test_unlink_multiple_file_a"; let file_b = "test_unlink_multiple_file_b"; at.touch(file_a); at.touch(file_b); - ucmd.arg(file_a).arg(file_b).fails().stderr_is( - "unlink: extra operand: 'test_unlink_multiple_file_b'\nTry 'unlink --help' \ - for more information.\n", - ); + ucmd.arg(file_a).arg(file_b).fails().stderr_is(&format!( + "{0}: extra operand: 'test_unlink_multiple_file_b'\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/common/util.rs b/tests/common/util.rs index 41389d567..5441b82c2 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -713,7 +713,7 @@ impl AtPath { /// /// Fixtures can be found under `tests/fixtures/$util_name/` pub struct TestScenario { - bin_path: PathBuf, + pub bin_path: PathBuf, pub util_name: String, pub fixtures: AtPath, tmpd: Rc, From 38f3d13f7fb46463619df6c701ce63f5fba7bfa2 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Tue, 27 Jul 2021 22:00:45 -0500 Subject: [PATCH 16/25] maint/CICD ~ pin code coverage utility `grcov` at v0.8.0 (v0.8.1 uses unstable `take()`) --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 8a1e142df..90b836c0f 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -625,7 +625,7 @@ jobs: uses: actions-rs/install@v0.1 with: crate: grcov - version: latest + version: 0.8.0 use-tool-cache: false - name: Generate coverage data (via `grcov`) id: coverage From 44981cab0123dfbb92476f3e1c07aaefcbb81d33 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Sat, 14 Aug 2021 13:50:53 +0200 Subject: [PATCH 17/25] refactor/uucore ~ correct implementation of executable!() for multicall - Use an atomic bool to track whether the utility name is the second or the first argument. - Add tests --- src/bin/coreutils.rs | 1 + src/uu/base32/src/base32.rs | 6 +-- src/uu/base64/src/base64.rs | 4 +- src/uucore/src/lib/lib.rs | 9 ++++ src/uucore/src/lib/macros.rs | 59 ++++++++++---------------- tests/test_util_name.rs | 81 ++++++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 43 deletions(-) create mode 100644 tests/test_util_name.rs diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 3e8df57f7..477931dbd 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -70,6 +70,7 @@ fn main() { Some(OsString::from(*util)) } else { // unmatched binary name => regard as multi-binary container and advance argument list + uucore::set_utility_is_second_arg(); args.next() }; diff --git a/src/uu/base32/src/base32.rs b/src/uu/base32/src/base32.rs index a93b4e18b..4d6c634e5 100644 --- a/src/uu/base32/src/base32.rs +++ b/src/uu/base32/src/base32.rs @@ -38,7 +38,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let name = util_name!(); let config_result: Result = - base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage); + base_common::parse_base_cmd_args(args, &name, VERSION, ABOUT, &usage); let config = config_result.unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s)); // Create a reference to stdin so we can return a locked stdin from @@ -52,12 +52,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 { config.wrap_cols, config.ignore_garbage, config.decode, - name, + &name, ); 0 } pub fn uu_app() -> App<'static, 'static> { - base_common::base_app(util_name!(), VERSION, ABOUT) + base_common::base_app(&util_name!(), VERSION, ABOUT) } diff --git a/src/uu/base64/src/base64.rs b/src/uu/base64/src/base64.rs index b53ec32e9..689940a07 100644 --- a/src/uu/base64/src/base64.rs +++ b/src/uu/base64/src/base64.rs @@ -38,7 +38,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let usage = usage(); let name = util_name!(); let config_result: Result = - base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage); + base_common::parse_base_cmd_args(args, &name, VERSION, ABOUT, &usage); let config = config_result.unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s)); // Create a reference to stdin so we can return a locked stdin from @@ -52,7 +52,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { config.wrap_cols, config.ignore_garbage, config.decode, - name, + &name, ); 0 diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index aa96a1086..8920b226d 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -77,6 +77,15 @@ pub use crate::features::wide; //## core functions use std::ffi::OsString; +use std::sync::atomic::Ordering; + +pub fn get_utility_is_second_arg() -> bool { + crate::macros::UTILITY_IS_SECOND_ARG.load(Ordering::SeqCst) +} + +pub fn set_utility_is_second_arg() { + crate::macros::UTILITY_IS_SECOND_ARG.store(true, Ordering::SeqCst) +} pub enum InvalidEncodingHandling { Ignore, diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index df3834f7e..72826be5f 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -1,3 +1,5 @@ +use std::sync::atomic::AtomicBool; + // This file is part of the uutils coreutils package. // // (c) Alex Lyon @@ -5,40 +7,22 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +/// Whether we were called as a multicall binary ("coreutils ") +pub static UTILITY_IS_SECOND_ARG: AtomicBool = AtomicBool::new(false); + /// Get the executable path (as `OsString`). #[macro_export] macro_rules! executable_os( () => ({ - &uucore::args_os().next().unwrap() + $crate::args_os().next().unwrap() }) ); -/// Get the executable path (as `String`; lossless). +/// Get the executable path (as `String`). #[macro_export] macro_rules! executable( () => ({ - let exe = match $crate::executable_os!().to_str() { - // * UTF-8 - Some(s) => s.to_string(), - // * "lossless" debug format (if/when `executable_os!()` is not well-formed UTF-8) - None => format!("{:?}", $crate::executable_os!()) - }; - &exe.to_owned() - }) -); - -/// Get the executable name. -#[macro_export] -macro_rules! executable_name( - () => ({ - let stem = &std::path::Path::new($crate::executable_os!()).file_stem().unwrap().to_owned(); - let exe = match stem.to_str() { - // * UTF-8 - Some(s) => s.to_string(), - // * "lossless" debug format (if/when `executable_os!()` is not well-formed UTF-8) - None => format!("{:?}", stem) - }; - &exe.to_owned() + $crate::executable_os!().to_string_lossy().to_string() }) ); @@ -46,13 +30,11 @@ macro_rules! executable_name( #[macro_export] macro_rules! util_name( () => ({ - let crate_name = env!("CARGO_PKG_NAME"); - let name = if crate_name.starts_with("uu_") { - &crate_name[3..] + if $crate::get_utility_is_second_arg() { + $crate::args_os().nth(1).unwrap().to_string_lossy().to_string() } else { - crate_name - }; - &name.to_owned() + $crate::executable!() + } }) ); @@ -62,14 +44,15 @@ macro_rules! util_name( #[macro_export] macro_rules! execution_phrase( () => ({ - let exe = if (executable_name!() == util_name!()) { - executable!().to_string() - } else { - format!("{} {}", executable!(), util_name!()) - .as_str() - .to_owned() - }; - &exe.to_owned() + if $crate::get_utility_is_second_arg() { + $crate::args_os() + .take(2) + .map(|os_str| os_str.to_string_lossy().to_string()) + .collect::>() + .join(" ") + } else { + $crate::executable!() + } }) ); diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs new file mode 100644 index 000000000..640fecd44 --- /dev/null +++ b/tests/test_util_name.rs @@ -0,0 +1,81 @@ +mod common; + +use common::util::TestScenario; + +#[test] +#[cfg(feature = "ls")] +fn execution_phrase_double() { + use std::process::Command; + + let scenario = TestScenario::new("ls"); + let output = Command::new(&scenario.bin_path) + .arg("ls") + .arg("--some-invalid-arg") + .output() + .unwrap(); + assert!(String::from_utf8(output.stderr) + .unwrap() + .contains(&format!("USAGE:\n {} ls", scenario.bin_path.display(),))); +} + +#[test] +#[cfg(feature = "ls")] +fn execution_phrase_single() { + use std::process::Command; + + let scenario = TestScenario::new("ls"); + std::fs::copy(scenario.bin_path, scenario.fixtures.plus("uu-ls")).unwrap(); + let output = Command::new(scenario.fixtures.plus("uu-ls")) + .arg("--some-invalid-arg") + .output() + .unwrap(); + assert!(String::from_utf8(output.stderr).unwrap().contains(&format!( + "USAGE:\n {}", + scenario.fixtures.plus("uu-ls").display() + ))); +} + +#[test] +#[cfg(feature = "sort")] +fn util_name_double() { + use std::{ + io::Write, + process::{Command, Stdio}, + }; + + let scenario = TestScenario::new("sort"); + let mut child = Command::new(&scenario.bin_path) + .arg("sort") + .stdin(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); + // input invalid utf8 to cause an error + child.stdin.take().unwrap().write_all(&[255]).unwrap(); + let output = child.wait_with_output().unwrap(); + assert!(String::from_utf8(output.stderr).unwrap().contains("sort: ")); +} + +#[test] +#[cfg(feature = "sort")] +fn util_name_single() { + use std::{ + io::Write, + process::{Command, Stdio}, + }; + + let scenario = TestScenario::new("sort"); + std::fs::copy(scenario.bin_path, scenario.fixtures.plus("uu-sort")).unwrap(); + let mut child = Command::new(scenario.fixtures.plus("uu-sort")) + .stdin(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); + // input invalid utf8 to cause an error + child.stdin.take().unwrap().write_all(&[255]).unwrap(); + let output = child.wait_with_output().unwrap(); + assert!(String::from_utf8(output.stderr).unwrap().contains(&format!( + "{}: ", + scenario.fixtures.plus("uu-sort").display() + ))); +} From 813b477859f4ca82ea8060431f84b55f150fee62 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Sat, 14 Aug 2021 14:10:35 +0200 Subject: [PATCH 18/25] fix ~ fixes for newly added utilities --- src/uu/basenc/src/basenc.rs | 12 ++++++------ src/uu/cat/src/cat.rs | 2 +- src/uu/chcon/src/chcon.rs | 8 ++++---- src/uu/dd/src/dd.rs | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/uu/basenc/src/basenc.rs b/src/uu/basenc/src/basenc.rs index e1daea4e6..ef9779512 100644 --- a/src/uu/basenc/src/basenc.rs +++ b/src/uu/basenc/src/basenc.rs @@ -42,12 +42,12 @@ const ENCODINGS: &[(&str, Format)] = &[ ("base2m", Format::Base2Msbf), ]; -fn get_usage() -> String { - format!("{0} [OPTION]... [FILE]", executable!()) +fn usage() -> String { + format!("{0} [OPTION]... [FILE]", execution_phrase!()) } pub fn uu_app() -> App<'static, 'static> { - let mut app = base_common::base_app(executable!(), crate_version!(), ABOUT); + let mut app = base_common::base_app(&util_name!(), crate_version!(), ABOUT); for encoding in ENCODINGS { app = app.arg(Arg::with_name(encoding.0).long(encoding.0)); } @@ -55,7 +55,7 @@ pub fn uu_app() -> App<'static, 'static> { } fn parse_cmd_args(args: impl uucore::Args) -> (Config, Format) { - let usage = get_usage(); + let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from( args.collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(), @@ -75,7 +75,7 @@ fn parse_cmd_args(args: impl uucore::Args) -> (Config, Format) { } pub fn uumain(args: impl uucore::Args) -> i32 { - let name = executable!(); + let name = util_name!(); let (config, format) = parse_cmd_args(args); // Create a reference to stdin so we can return a locked stdin from // parse_base_cmd_args @@ -88,7 +88,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { config.wrap_cols, config.ignore_garbage, config.decode, - name, + &name, ); 0 diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index cb12830a4..e0c7d2226 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -396,7 +396,7 @@ fn cat_files(files: Vec, options: &OutputOptions) -> UResult<()> { Ok(()) } else { // each next line is expected to display "cat: …" - let line_joiner = format!("\n{}: ", executable!()); + let line_joiner = format!("\n{}: ", util_name!()); Err(uucore::error::USimpleError::new( error_messages.len() as i32, diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 2a5efba46..6f45dcd92 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -2,7 +2,7 @@ #![allow(clippy::upper_case_acronyms)] -use uucore::{executable, show_error, show_usage_error, show_warning}; +use uucore::{execution_phrase, show_error, show_usage_error, show_warning, util_name}; use clap::{App, Arg}; use selinux::{OpaqueSecurityContext, SecurityContext}; @@ -56,7 +56,7 @@ fn get_usage() -> String { "{0} [OPTION]... CONTEXT FILE... \n \ {0} [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... \n \ {0} [OPTION]... --reference=RFILE FILE...", - executable!() + execution_phrase!() ) } @@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(executable!()) + App::new(util_name!()) .version(VERSION) .about(ABOUT) .arg( @@ -563,7 +563,7 @@ fn process_file( if options.verbose { println!( "{}: Changing security context of: {}", - executable!(), + util_name!(), file_full_name.to_string_lossy() ); } diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index b300dff2d..660f62f7a 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -1046,7 +1046,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> clap::App<'static, 'static> { - clap::App::new(executable!()) + clap::App::new(util_name!()) .version(crate_version!()) .about(ABOUT) .arg( From 303908352109b549e860aa93313055bf457f7ec1 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Sat, 14 Aug 2021 14:19:05 +0200 Subject: [PATCH 19/25] refactor/uucore ~ mark executable!() as deprecated Make sure that utilities do not use it anymore. It is only allowed as an implementation detail of util_name!() and execution_phrase!() --- src/uucore/src/lib/macros.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 72826be5f..3d389d83d 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -20,6 +20,7 @@ macro_rules! executable_os( /// Get the executable path (as `String`). #[macro_export] +#[deprecated = "Use util_name!() or execution_phrase!() instead"] macro_rules! executable( () => ({ $crate::executable_os!().to_string_lossy().to_string() @@ -33,7 +34,10 @@ macro_rules! util_name( if $crate::get_utility_is_second_arg() { $crate::args_os().nth(1).unwrap().to_string_lossy().to_string() } else { - $crate::executable!() + #[allow(deprecated)] + { + $crate::executable!() + } } }) ); @@ -51,7 +55,10 @@ macro_rules! execution_phrase( .collect::>() .join(" ") } else { - $crate::executable!() + #[allow(deprecated)] + { + $crate::executable!() + } } }) ); From 6ab3d27c4e0ef105a6007c926175f8dbdc968507 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Sat, 14 Aug 2021 14:48:38 +0200 Subject: [PATCH 20/25] fix ~ remove redundant clone() util_name!() and execution_phrare!() now return a String directly --- src/uu/du/src/du.rs | 2 +- src/uu/logname/src/logname.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 2c430d693..629247f29 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -466,7 +466,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let options = Options { all: matches.is_present(options::ALL), - util_name: util_name!().to_string(), + util_name: util_name!(), max_depth, total: matches.is_present(options::TOTAL), separate_dirs: matches.is_present(options::SEPARATE_DIRS), diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index e9952ddef..1a69543c1 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -36,7 +36,7 @@ fn get_userlogin() -> Option { static SUMMARY: &str = "Print user's login name"; fn usage() -> String { - execution_phrase!().to_string() + execution_phrase!() } pub fn uumain(args: impl uucore::Args) -> i32 { From 5f2335829a846b964829579de7a424116a57e550 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Sat, 14 Aug 2021 17:21:18 +0200 Subject: [PATCH 21/25] refactor ~ revert to single quotes for "Try '{0 --help'" This is a test expectation for gnu. --- 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 | 2 +- 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 | 2 +- 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 | 2 +- src/uu/tr/src/tr.rs | 4 ++-- src/uu/unlink/src/unlink.rs | 4 ++-- src/uucore/src/lib/macros.rs | 2 +- src/uucore_procs/src/lib.rs | 2 +- tests/by-util/test_basename.rs | 4 ++-- tests/by-util/test_cp.rs | 2 +- tests/by-util/test_more.rs | 2 +- tests/by-util/test_mv.rs | 2 +- tests/by-util/test_nice.rs | 2 +- tests/by-util/test_seq.rs | 4 ++-- tests/by-util/test_stdbuf.rs | 2 +- tests/by-util/test_unlink.rs | 2 +- 25 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index 8de55af80..d7aa52289 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.", execution_phrase!(), "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.", execution_phrase!(), 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 b622b51a1..71a12b052 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -45,7 +45,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.", execution_phrase!() ), }; diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 086b734e8..a3b3db9a5 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 `{} --help` for more information.", description, execution_phrase!()) } + Backup(description: String) { display("{}\nTry '{} --help' for more information.", description, execution_phrase!()) } } } diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 629247f29..52750cb95 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -422,7 +422,7 @@ Valid arguments are: - 'full-iso' - 'long-iso' - 'iso' -Try `{} --help` for more information.", +Try '{} --help' for more information.", s, execution_phrase!() ), diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 62748ae78..817aa91cb 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, execution_phrase!() ), diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 19c61bcfe..1a52de14f 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.", execution_phrase!()); + eprintln!("Try '{} --help' for more information.", execution_phrase!()); 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.", execution_phrase!()); + eprintln!("Try '{} --help' for more information.", execution_phrase!()); 1 } (Some(major), Some(minor)) => { diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index ecd57ee5a..1cf45c36a 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(), execution_phrase!() ); diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index 835034b74..a93137c10 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.", execution_phrase!() ); return 125; diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 65c917ac0..c1ea76bf9 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -69,7 +69,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let paths = matches.values_of(options::PATH); let mut res = if paths.is_none() { show_error!( - "missing operand\nTry `{} --help` for more information", + "missing operand\nTry '{} --help' for more information", execution_phrase!() ); false diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index 26a1b29b2..22e02ffe2 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -283,7 +283,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if args.len() <= 1 { println!( - "{0}: missing operand\nTry `{1} --help` for more information.", + "{0}: missing operand\nTry '{1} --help' for more information.", util_name!(), execution_phrase!() ); diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index cf788c1fe..81d8376f6 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -58,7 +58,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", execution_phrase!() ); } diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index f3e57881e..db5537b8b 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, execution_phrase!(), )), 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, execution_phrase!(), )), @@ -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], execution_phrase!() ); diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 87e478b73..a16a40ce5 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -159,7 +159,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let options = ProgramOptions::try_from(&matches).unwrap_or_else(|e| { crash!( 125, - "{}\nTry `{} --help` for more information.", + "{}\nTry '{} --help' for more information.", e.0, execution_phrase!() ) diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 0a277d663..7b6fbd6f2 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -263,7 +263,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if sets.is_empty() { show_error!( - "missing operand\nTry `{} --help` for more information.", + "missing operand\nTry '{} --help' for more information.", execution_phrase!() ); return 1; @@ -271,7 +271,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if !(delete_flag || squeeze_flag) && sets.len() < 2 { show_error!( - "missing operand after '{}'\nTry `{} --help` for more information.", + "missing operand after '{}'\nTry '{} --help' for more information.", sets[0], execution_phrase!() ); diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index 182729fd4..e0a743c1c 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.", execution_phrase!() ); } 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.", execution_phrase!(), paths[1] ); diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index 3d389d83d..c9fff455a 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -115,7 +115,7 @@ macro_rules! show_usage_error( ($($args:tt)+) => ({ eprint!("{}: ", $crate::util_name!()); eprintln!($($args)+); - eprintln!("Try `{} --help` for more information.", $crate::execution_phrase!()); + eprintln!("Try '{} --help' for more information.", $crate::execution_phrase!()); }) ); diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index 74ac60220..7f7460283 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.", execution_phrase!()); + eprintln!("Try '{} --help' for more information.", execution_phrase!()); } e.code() } diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index 9701e9973..02dfebeda 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -116,7 +116,7 @@ fn test_no_args() { fn test_no_args_output() { let ts = TestScenario::new(util_name!()); ts.ucmd().fails().stderr_is(&format!( - "{0}: missing operand\nTry `{1} {0} --help` for more information.", + "{0}: missing operand\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() )); @@ -131,7 +131,7 @@ fn test_too_many_args() { fn test_too_many_args_output() { let ts = TestScenario::new(util_name!()); ts.ucmd().args(&["a", "b", "c"]).fails().stderr_is(format!( - "{0}: extra operand 'c'\nTry `{1} {0} --help` for more information.", + "{0}: extra operand 'c'\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() )); diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 6d739f448..b6b4c3311 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -568,7 +568,7 @@ fn test_cp_backup_no_clobber_conflicting_options() { .arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE) .fails().stderr_is(&format!( - "{0}: options --backup and --no-clobber are mutually exclusive\nTry `{1} {0} --help` for more information.", + "{0}: options --backup and --no-clobber are mutually exclusive\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() )); diff --git a/tests/by-util/test_more.rs b/tests/by-util/test_more.rs index a422b23a5..4b2719d8f 100644 --- a/tests/by-util/test_more.rs +++ b/tests/by-util/test_more.rs @@ -19,7 +19,7 @@ fn test_more_dir_arg() { let result = ts.ucmd().arg(".").run(); result.failure(); let expected_error_message = &format!( - "{0}: '.' is a directory.\nTry `{1} {0} --help` for more information.", + "{0}: '.' is a directory.\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() ); diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 8596f8477..8d9b00664 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -529,7 +529,7 @@ fn test_mv_backup_no_clobber_conflicting_options() { .arg("file1") .arg("file2") .fails() - .stderr_is(&format!("{0}: options --backup and --no-clobber are mutually exclusive\nTry `{1} {0} --help` for more information.", + .stderr_is(&format!("{0}: options --backup and --no-clobber are mutually exclusive\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() )); diff --git a/tests/by-util/test_nice.rs b/tests/by-util/test_nice.rs index 639fa5697..7a99a333d 100644 --- a/tests/by-util/test_nice.rs +++ b/tests/by-util/test_nice.rs @@ -27,7 +27,7 @@ fn test_adjustment_with_no_command_should_error() { ts.ucmd() .args(&["-n", "19"]) .run() - .stderr_is(&format!("{0}: A command must be given with an adjustment.\nTry `{1} {0} --help` for more information.\n", + .stderr_is(&format!("{0}: A command must be given with an adjustment.\nTry '{1} {0} --help' for more information.\n", ts.util_name, ts.bin_path.to_string_lossy() )); diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index cc94d4b1f..eab7e16ce 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -5,7 +5,7 @@ fn test_rejects_nan() { let ts = TestScenario::new(util_name!()); ts.ucmd().args(&["NaN"]).fails().stderr_only(format!( - "{0}: invalid 'not-a-number' argument: 'NaN'\nTry `{1} {0} --help` for more information.", + "{0}: invalid 'not-a-number' argument: 'NaN'\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() )); @@ -16,7 +16,7 @@ fn test_rejects_non_floats() { let ts = TestScenario::new(util_name!()); ts.ucmd().args(&["foo"]).fails().stderr_only(&format!( - "{0}: invalid floating point argument: 'foo'\nTry `{1} {0} --help` for more information.", + "{0}: invalid floating point argument: 'foo'\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() )); diff --git a/tests/by-util/test_stdbuf.rs b/tests/by-util/test_stdbuf.rs index d705c0854..c05b65d70 100644 --- a/tests/by-util/test_stdbuf.rs +++ b/tests/by-util/test_stdbuf.rs @@ -59,7 +59,7 @@ fn test_stdbuf_line_buffering_stdin_fails() { .args(&["-i", "L", "head"]) .fails() .stderr_is(&format!( - "{0}: line buffering stdin is meaningless\nTry `{1} {0} --help` for more information.", + "{0}: line buffering stdin is meaningless\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() )); diff --git a/tests/by-util/test_unlink.rs b/tests/by-util/test_unlink.rs index 0c82b6a39..36c978734 100644 --- a/tests/by-util/test_unlink.rs +++ b/tests/by-util/test_unlink.rs @@ -24,7 +24,7 @@ fn test_unlink_multiple_files() { at.touch(file_b); ucmd.arg(file_a).arg(file_b).fails().stderr_is(&format!( - "{0}: extra operand: 'test_unlink_multiple_file_b'\nTry `{1} {0} --help` for more information.", + "{0}: extra operand: 'test_unlink_multiple_file_b'\nTry '{1} {0} --help' for more information.", ts.util_name, ts.bin_path.to_string_lossy() )); From 252220e9eb5b97719f74e1ed163d88eaa20f8463 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Sat, 14 Aug 2021 17:55:14 +0200 Subject: [PATCH 22/25] refactor/uucore ~ make util_name and execution_phrase functions Since util_name and execution_phrase no longer rely on features that are only available to macros, they may as well be plain functions. --- src/uu/arch/src/arch.rs | 2 +- src/uu/base32/src/base32.rs | 6 +-- src/uu/base64/src/base64.rs | 4 +- src/uu/basename/src/basename.rs | 8 ++-- src/uu/basenc/src/basenc.rs | 6 +-- src/uu/cat/src/cat.rs | 4 +- src/uu/chcon/src/chcon.rs | 8 ++-- src/uu/chgrp/src/chgrp.rs | 4 +- src/uu/chmod/src/chmod.rs | 4 +- src/uu/chown/src/chown.rs | 4 +- src/uu/chroot/src/chroot.rs | 6 +-- src/uu/cksum/src/cksum.rs | 2 +- src/uu/comm/src/comm.rs | 7 +-- src/uu/cp/src/cp.rs | 8 ++-- src/uu/csplit/src/csplit.rs | 7 ++- src/uu/cut/src/cut.rs | 2 +- src/uu/date/src/date.rs | 5 +-- src/uu/dd/src/dd.rs | 4 +- src/uu/df/src/df.rs | 6 +-- src/uu/dircolors/src/dircolors.rs | 4 +- src/uu/dirname/src/dirname.rs | 4 +- src/uu/du/src/du.rs | 8 ++-- src/uu/echo/src/echo.rs | 2 +- src/uu/expand/src/expand.rs | 4 +- src/uu/expr/src/expr.rs | 4 +- src/uu/factor/src/cli.rs | 2 +- src/uu/false/src/false.rs | 3 +- src/uu/fmt/src/fmt.rs | 4 +- src/uu/fold/src/fold.rs | 2 +- src/uu/groups/src/groups.rs | 4 +- src/uu/hashsum/src/hashsum.rs | 2 +- src/uu/head/src/head.rs | 4 +- src/uu/hostid/src/hostid.rs | 2 +- src/uu/hostname/src/hostname.rs | 4 +- src/uu/id/src/id.rs | 4 +- src/uu/install/src/install.rs | 16 ++++--- src/uu/kill/src/kill.rs | 4 +- src/uu/link/src/link.rs | 4 +- src/uu/ln/src/ln.rs | 8 ++-- src/uu/logname/src/logname.rs | 4 +- src/uu/ls/src/ls.rs | 4 +- src/uu/mkdir/src/mkdir.rs | 10 +++-- src/uu/mkfifo/src/mkfifo.rs | 2 +- src/uu/mknod/src/mknod.rs | 16 ++++--- src/uu/mktemp/src/mktemp.rs | 4 +- src/uu/more/src/more.rs | 2 +- src/uu/mv/src/mv.rs | 8 ++-- src/uu/nice/src/nice.rs | 6 +-- src/uu/nl/src/nl.rs | 2 +- src/uu/nohup/src/nohup.rs | 7 ++- src/uu/nproc/src/nproc.rs | 4 +- src/uu/numfmt/src/numfmt.rs | 4 +- src/uu/od/src/multifilereader.rs | 4 +- src/uu/od/src/od.rs | 2 +- src/uu/paste/src/paste.rs | 2 +- src/uu/pathchk/src/pathchk.rs | 6 +-- src/uu/pinky/src/pinky.rs | 4 +- src/uu/pr/src/pr.rs | 3 +- src/uu/printenv/src/printenv.rs | 7 +-- src/uu/printf/src/printf.rs | 11 ++--- src/uu/ptx/src/ptx.rs | 2 +- src/uu/pwd/src/pwd.rs | 4 +- src/uu/readlink/src/readlink.rs | 12 +++--- src/uu/realpath/src/realpath.rs | 4 +- src/uu/relpath/src/relpath.rs | 7 +-- src/uu/rm/src/rm.rs | 6 +-- src/uu/rmdir/src/rmdir.rs | 4 +- src/uu/seq/src/seq.rs | 10 ++--- src/uu/shred/src/shred.rs | 4 +- src/uu/shuf/src/shuf.rs | 2 +- src/uu/sleep/src/sleep.rs | 4 +- src/uu/sort/src/sort.rs | 4 +- src/uu/split/src/split.rs | 7 ++- src/uu/stat/src/stat.rs | 4 +- src/uu/stdbuf/src/stdbuf.rs | 6 +-- src/uu/sum/src/sum.rs | 2 +- src/uu/sync/src/sync.rs | 4 +- src/uu/tac/src/tac.rs | 2 +- src/uu/tail/src/tail.rs | 2 +- src/uu/tee/src/tee.rs | 4 +- src/uu/test/src/test.rs | 3 +- src/uu/timeout/src/timeout.rs | 5 ++- src/uu/touch/src/touch.rs | 4 +- src/uu/tr/src/tr.rs | 8 ++-- src/uu/true/src/true.rs | 3 +- src/uu/truncate/src/truncate.rs | 4 +- src/uu/tsort/src/tsort.rs | 2 +- src/uu/tty/src/tty.rs | 7 +-- src/uu/uname/src/uname.rs | 4 +- src/uu/unexpand/src/unexpand.rs | 2 +- src/uu/uniq/src/uniq.rs | 7 ++- src/uu/unlink/src/unlink.rs | 8 ++-- src/uu/uptime/src/uptime.rs | 4 +- src/uu/users/src/users.rs | 7 +-- src/uu/wc/src/wc.rs | 4 +- src/uu/who/src/who.rs | 7 ++- src/uucore/src/lib/lib.rs | 32 ++++++++++++++ src/uucore/src/lib/macros.rs | 67 +++-------------------------- src/uucore/src/lib/mods/coreopts.rs | 4 +- src/uucore_procs/src/lib.rs | 2 +- 100 files changed, 279 insertions(+), 297 deletions(-) diff --git a/src/uu/arch/src/arch.rs b/src/uu/arch/src/arch.rs index 30adbaad9..478fef6f1 100644 --- a/src/uu/arch/src/arch.rs +++ b/src/uu/arch/src/arch.rs @@ -27,7 +27,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(SUMMARY) diff --git a/src/uu/base32/src/base32.rs b/src/uu/base32/src/base32.rs index 4d6c634e5..ac9ed1075 100644 --- a/src/uu/base32/src/base32.rs +++ b/src/uu/base32/src/base32.rs @@ -29,13 +29,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); static BASE_CMD_PARSE_ERROR: i32 = 1; fn usage() -> String { - format!("{0} [OPTION]... [FILE]", execution_phrase!()) + format!("{0} [OPTION]... [FILE]", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { let format = Format::Base32; let usage = usage(); - let name = util_name!(); + let name = uucore::util_name(); let config_result: Result = base_common::parse_base_cmd_args(args, &name, VERSION, ABOUT, &usage); @@ -59,5 +59,5 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - base_common::base_app(&util_name!(), VERSION, ABOUT) + base_common::base_app(&uucore::util_name(), VERSION, ABOUT) } diff --git a/src/uu/base64/src/base64.rs b/src/uu/base64/src/base64.rs index 689940a07..e303f9d29 100644 --- a/src/uu/base64/src/base64.rs +++ b/src/uu/base64/src/base64.rs @@ -30,13 +30,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); static BASE_CMD_PARSE_ERROR: i32 = 1; fn usage() -> String { - format!("{0} [OPTION]... [FILE]", execution_phrase!()) + format!("{0} [OPTION]... [FILE]", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { let format = Format::Base64; let usage = usage(); - let name = util_name!(); + let name = uucore::util_name(); let config_result: Result = base_common::parse_base_cmd_args(args, &name, VERSION, ABOUT, &usage); let config = config_result.unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s)); diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index d7aa52289..2d2f649d1 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -21,7 +21,7 @@ fn usage() -> String { format!( "{0} NAME [SUFFIX] {0} OPTION... NAME...", - execution_phrase!() + uucore::execution_phrase() ) } @@ -47,7 +47,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "{1}\nTry '{0} --help' for more information.", - execution_phrase!(), + uucore::execution_phrase(), "missing operand" ); } @@ -61,7 +61,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "extra operand '{1}'\nTry '{0} --help' for more information.", - execution_phrase!(), + uucore::execution_phrase(), matches.values_of(options::NAME).unwrap().nth(2).unwrap() ); } @@ -93,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(SUMMARY) .arg( diff --git a/src/uu/basenc/src/basenc.rs b/src/uu/basenc/src/basenc.rs index ef9779512..2b3193d49 100644 --- a/src/uu/basenc/src/basenc.rs +++ b/src/uu/basenc/src/basenc.rs @@ -43,11 +43,11 @@ const ENCODINGS: &[(&str, Format)] = &[ ]; fn usage() -> String { - format!("{0} [OPTION]... [FILE]", execution_phrase!()) + format!("{0} [OPTION]... [FILE]", uucore::execution_phrase()) } pub fn uu_app() -> App<'static, 'static> { - let mut app = base_common::base_app(&util_name!(), crate_version!(), ABOUT); + let mut app = base_common::base_app(&uucore::util_name(), crate_version!(), ABOUT); for encoding in ENCODINGS { app = app.arg(Arg::with_name(encoding.0).long(encoding.0)); } @@ -75,7 +75,7 @@ fn parse_cmd_args(args: impl uucore::Args) -> (Config, Format) { } pub fn uumain(args: impl uucore::Args) -> i32 { - let name = util_name!(); + let name = uucore::util_name(); let (config, format) = parse_cmd_args(args); // Create a reference to stdin so we can return a locked stdin from // parse_base_cmd_args diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index e0c7d2226..a176b8c5d 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -234,7 +234,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(SYNTAX) @@ -396,7 +396,7 @@ fn cat_files(files: Vec, options: &OutputOptions) -> UResult<()> { Ok(()) } else { // each next line is expected to display "cat: …" - let line_joiner = format!("\n{}: ", util_name!()); + let line_joiner = format!("\n{}: ", uucore::util_name()); Err(uucore::error::USimpleError::new( error_messages.len() as i32, diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 6f45dcd92..5f6a80bde 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -2,7 +2,7 @@ #![allow(clippy::upper_case_acronyms)] -use uucore::{execution_phrase, show_error, show_usage_error, show_warning, util_name}; +use uucore::{show_error, show_usage_error, show_warning}; use clap::{App, Arg}; use selinux::{OpaqueSecurityContext, SecurityContext}; @@ -56,7 +56,7 @@ fn get_usage() -> String { "{0} [OPTION]... CONTEXT FILE... \n \ {0} [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... \n \ {0} [OPTION]... --reference=RFILE FILE...", - execution_phrase!() + uucore::execution_phrase() ) } @@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(VERSION) .about(ABOUT) .arg( @@ -563,7 +563,7 @@ fn process_file( if options.verbose { println!( "{}: Changing security context of: {}", - util_name!(), + uucore::util_name(), file_full_name.to_string_lossy() ); } diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index 5dbcc277e..7840ba829 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -62,7 +62,7 @@ const FTS_LOGICAL: u8 = 1 << 2; fn usage() -> String { format!( "{0} [OPTION]... GROUP FILE...\n {0} [OPTION]... --reference=RFILE FILE...", - execution_phrase!() + uucore::execution_phrase() ) } @@ -197,7 +197,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(VERSION) .about(ABOUT) .arg( diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 88ad22969..5108ec924 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -41,7 +41,7 @@ fn usage() -> String { "{0} [OPTION]... MODE[,MODE]... FILE... or: {0} [OPTION]... OCTAL-MODE FILE... or: {0} [OPTION]... --reference=RFILE FILE...", - execution_phrase!() + uucore::execution_phrase() ) } @@ -116,7 +116,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index a7824f248..8813c07e2 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -64,7 +64,7 @@ const FTS_LOGICAL: u8 = 1 << 2; fn usage() -> String { format!( "{0} [OPTION]... [OWNER][:[GROUP]] FILE...\n{0} [OPTION]... --reference=RFILE FILE...", - execution_phrase!() + uucore::execution_phrase() ) } @@ -165,7 +165,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 71a12b052..c0f392913 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -16,7 +16,7 @@ use std::io::Error; use std::path::Path; use std::process::Command; use uucore::libc::{self, chroot, setgid, setgroups, setuid}; -use uucore::{entries, execution_phrase, InvalidEncodingHandling}; +use uucore::{entries, InvalidEncodingHandling}; static ABOUT: &str = "Run COMMAND with root directory set to NEWROOT."; static SYNTAX: &str = "[OPTION]... NEWROOT [COMMAND [ARG]...]"; @@ -46,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { None => crash!( 1, "Missing operand: NEWROOT\nTry '{} --help' for more information.", - execution_phrase!() + uucore::execution_phrase() ), }; @@ -91,7 +91,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .usage(SYNTAX) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 8173fa451..a5beec368 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .about(SUMMARY) diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index 02c5598be..56af42fd9 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -7,9 +7,6 @@ // spell-checker:ignore (ToDO) delim mkdelim -#[macro_use] -extern crate uucore; - use std::cmp::Ordering; use std::fs::File; use std::io::{self, stdin, BufRead, BufReader, Stdin}; @@ -32,7 +29,7 @@ mod options { } fn usage() -> String { - format!("{} [OPTION]... FILE1 FILE2", execution_phrase!()) + format!("{} [OPTION]... FILE1 FILE2", uucore::execution_phrase()) } fn mkdelim(col: usize, opts: &ArgMatches) -> String { @@ -148,7 +145,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index a3b3db9a5..01d7d11be 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 '{} --help' for more information.", description, execution_phrase!()) } + Backup(description: String) { display("{}\nTry '{} --help' for more information.", description, uucore::execution_phrase()) } } } @@ -223,7 +223,7 @@ fn usage() -> String { "{0} [OPTION]... [-T] SOURCE DEST {0} [OPTION]... SOURCE... DIRECTORY {0} [OPTION]... -t DIRECTORY SOURCE...", - execution_phrase!() + uucore::execution_phrase() ) } @@ -293,7 +293,7 @@ static DEFAULT_ATTRIBUTES: &[Attribute] = &[ ]; pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg(Arg::with_name(options::TARGET_DIRECTORY) @@ -1060,7 +1060,7 @@ impl OverwriteMode { match *self { OverwriteMode::NoClobber => Err(Error::NotAllFilesCopied), OverwriteMode::Interactive(_) => { - if prompt_yes!("{}: overwrite {}? ", util_name!(), path.display()) { + if prompt_yes!("{}: overwrite {}? ", uucore::util_name(), path.display()) { Ok(()) } else { Err(Error::Skipped(format!( diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index c89d06cf3..9e93bbe42 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -35,7 +35,10 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]... FILE PATTERN...", execution_phrase!()) + format!( + "{0} [OPTION]... FILE PATTERN...", + uucore::execution_phrase() + ) } /// Command line options for csplit. @@ -739,7 +742,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(SUMMARY) .arg( diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 6410b9efc..783502e3d 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -548,7 +548,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(SYNTAX) diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 3d2a8c6d0..7bf6298c0 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -8,9 +8,6 @@ // spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes -#[macro_use] -extern crate uucore; - use chrono::{DateTime, FixedOffset, Local, Offset, Utc}; #[cfg(windows)] use chrono::{Datelike, Timelike}; @@ -253,7 +250,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 660f62f7a..c339398e6 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -7,8 +7,6 @@ // spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat -#[macro_use] -extern crate uucore; use uucore::InvalidEncodingHandling; #[cfg(test)] @@ -1046,7 +1044,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> clap::App<'static, 'static> { - clap::App::new(util_name!()) + clap::App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 52fae4702..e7f3944a0 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -80,7 +80,7 @@ struct Filesystem { } fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", execution_phrase!()) + format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase()) } impl FsSelector { @@ -295,7 +295,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { #[cfg(windows)] { if matches.is_present(OPT_INODES) { - println!("{}: doesn't support -i option", util_name!()); + println!("{}: doesn't support -i option", uucore::util_name()); return Ok(()); } } @@ -427,7 +427,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index c70fd97ee..2b9c25ba3 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -63,7 +63,7 @@ pub fn guess_syntax() -> OutputFmt { } fn usage() -> String { - format!("{0} {1}", execution_phrase!(), SYNTAX) + format!("{0} {1}", uucore::execution_phrase(), SYNTAX) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -153,7 +153,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(SUMMARY) .after_help(LONG_HELP) diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 4600d67ac..3e91d598a 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -21,7 +21,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION] NAME...", execution_phrase!()) + format!("{0} [OPTION] NAME...", uucore::execution_phrase()) } fn get_long_usage() -> String { @@ -86,7 +86,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .about(ABOUT) .version(crate_version!()) .arg( diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 52750cb95..258d58bae 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -396,7 +396,7 @@ fn usage() -> String { format!( "{0} [OPTION]... [FILE]... {0} [OPTION]... --files0-from=F", - execution_phrase!() + uucore::execution_phrase() ) } @@ -424,7 +424,7 @@ Valid arguments are: - 'iso' Try '{} --help' for more information.", s, - execution_phrase!() + uucore::execution_phrase() ), 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), - util_name: util_name!(), + util_name: uucore::util_name(), max_depth, total: matches.is_present(options::TOTAL), separate_dirs: matches.is_present(options::SEPARATE_DIRS), @@ -625,7 +625,7 @@ fn parse_depth(max_depth_str: Option<&str>, summarize: bool) -> UResult App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(SUMMARY) .after_help(LONG_HELP) diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index d34460df0..601fd8d48 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -132,7 +132,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) // TrailingVarArg specifies the final positional argument is a VarArg // and it doesn't attempts the parse any further args. diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 0cd4b2719..04cb42649 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -33,7 +33,7 @@ static LONG_HELP: &str = ""; static DEFAULT_TABSTOP: usize = 8; fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", execution_phrase!()) + format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase()) } /// The mode to use when replacing tabs beyond the last one specified in @@ -178,7 +178,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index 0a9d76f67..2d82300ff 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -18,7 +18,7 @@ const VERSION: &str = "version"; const HELP: &str = "help"; pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .arg(Arg::with_name(VERSION).long(VERSION)) .arg(Arg::with_name(HELP).long(HELP)) } @@ -140,5 +140,5 @@ Environment variables: } fn print_version() { - println!("{} {}", util_name!(), crate_version!()); + println!("{} {}", uucore::util_name(), crate_version!()); } diff --git a/src/uu/factor/src/cli.rs b/src/uu/factor/src/cli.rs index 628ded969..95b8bb866 100644 --- a/src/uu/factor/src/cli.rs +++ b/src/uu/factor/src/cli.rs @@ -75,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(SUMMARY) .arg(Arg::with_name(options::NUMBER).multiple(true)) diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 8f7710912..88ec1af06 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -10,7 +10,6 @@ extern crate uucore; use clap::App; use uucore::error::UResult; -use uucore::util_name; #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { @@ -19,5 +18,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) } diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index d42151503..5203745a1 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -51,7 +51,7 @@ static OPT_TAB_WIDTH: &str = "tab-width"; static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{} [OPTION]... [FILE]...", execution_phrase!()) + format!("{} [OPTION]... [FILE]...", uucore::execution_phrase()) } pub type FileOrStdReader = BufReader>; @@ -211,7 +211,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index a2321d5ee..c5628125d 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(SYNTAX) diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index 83be0932b..c2af5c4b0 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -29,7 +29,7 @@ static ABOUT: &str = "Print group memberships for each USERNAME or, \ (which may differ if the groups data‐base has changed)."; fn usage() -> String { - format!("{0} [OPTION]... [USERNAME]...", execution_phrase!()) + format!("{0} [OPTION]... [USERNAME]...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -85,7 +85,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 332e08009..77cc0d558 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -342,7 +342,7 @@ pub fn uu_app_common() -> App<'static, 'static> { const TEXT_HELP: &str = "read in text mode"; #[cfg(not(windows))] const TEXT_HELP: &str = "read in text mode (default)"; - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about("Compute and check message digests.") .arg( diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index 11ea56449..e47488ac4 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -9,7 +9,7 @@ use clap::{crate_version, App, Arg}; use std::convert::TryFrom; use std::ffi::OsString; use std::io::{self, ErrorKind, Read, Seek, SeekFrom, Write}; -use uucore::{crash, show_error_custom_description, util_name}; +use uucore::{crash, show_error_custom_description}; const EXIT_FAILURE: i32 = 1; const EXIT_SUCCESS: i32 = 0; @@ -41,7 +41,7 @@ use lines::zlines; use take::take_all_but; pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .usage(USAGE) diff --git a/src/uu/hostid/src/hostid.rs b/src/uu/hostid/src/hostid.rs index e593ff7ee..4c9cafa35 100644 --- a/src/uu/hostid/src/hostid.rs +++ b/src/uu/hostid/src/hostid.rs @@ -29,7 +29,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .usage(SYNTAX) } diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index 2dc68abfb..8852e0f43 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } fn usage() -> String { - format!("{0} [OPTION]... [HOSTNAME]", execution_phrase!()) + format!("{0} [OPTION]... [HOSTNAME]", uucore::execution_phrase()) } fn execute(args: impl uucore::Args) -> UResult<()> { @@ -74,7 +74,7 @@ fn execute(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 74523213e..4e8e30e52 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -77,7 +77,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]... [USER]...", execution_phrase!()) + format!("{0} [OPTION]... [USER]...", uucore::execution_phrase()) } fn get_description() -> String { @@ -347,7 +347,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index a1c6d4225..5c951ad5b 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -86,11 +86,13 @@ impl Display for InstallError { use InstallError as IE; match self { IE::Unimplemented(opt) => write!(f, "Unimplemented feature: {}", opt), - IE::DirNeedsArg() => write!( - f, - "{} with -d requires at least one argument.", - util_name!() - ), + IE::DirNeedsArg() => { + write!( + f, + "{} with -d requires at least one argument.", + uucore::util_name() + ) + } IE::CreateDirFailed(dir, e) => { Display::fmt(&uio_error!(e, "failed to create {}", dir.display()), f) } @@ -173,7 +175,7 @@ static OPT_CONTEXT: &str = "context"; static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", execution_phrase!()) + format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase()) } /// Main install utility function, called from main.rs. @@ -202,7 +204,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 08dff87d4..47bd97dbc 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -41,7 +41,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .accept_any(); let (args, obs_signal) = handle_obsolete(args); - let usage = format!("{} [OPTIONS]... PID...", execution_phrase!()); + let usage = format!("{} [OPTIONS]... PID...", uucore::execution_phrase()); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let mode = if matches.is_present(options::TABLE) || matches.is_present(options::TABLE_OLD) { @@ -76,7 +76,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/link/src/link.rs b/src/uu/link/src/link.rs index 03dd46aee..73e81b107 100644 --- a/src/uu/link/src/link.rs +++ b/src/uu/link/src/link.rs @@ -20,7 +20,7 @@ pub mod options { } fn usage() -> String { - format!("{0} FILE1 FILE2", execution_phrase!()) + format!("{0} FILE1 FILE2", uucore::execution_phrase()) } pub fn normalize_error_message(e: Error) -> String { @@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 817aa91cb..c24db2172 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -70,7 +70,7 @@ impl Display for LnError { f, "extra operand '{}'\nTry '{} --help' for more information.", s, - execution_phrase!() + uucore::execution_phrase() ), Self::InvalidBackupMode(s) => write!(f, "{}", s), } @@ -98,7 +98,7 @@ fn usage() -> String { {0} [OPTION]... TARGET (2nd form) {0} [OPTION]... TARGET... DIRECTORY (3rd form) {0} [OPTION]... -t DIRECTORY TARGET... (4th form)", - execution_phrase!() + uucore::execution_phrase() ) } @@ -196,7 +196,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( @@ -431,7 +431,7 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> Result<()> { match settings.overwrite { OverwriteMode::NoClobber => {} OverwriteMode::Interactive => { - print!("{}: overwrite '{}'? ", util_name!(), dst.display()); + print!("{}: overwrite '{}'? ", uucore::util_name(), dst.display()); if !read_yes() { return Ok(()); } diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 1a69543c1..f8dd3fc5d 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -36,7 +36,7 @@ fn get_userlogin() -> Option { static SUMMARY: &str = "Print user's login name"; fn usage() -> String { - execution_phrase!() + uucore::execution_phrase() } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -56,7 +56,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(SUMMARY) } diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 6ba3ec4f1..da8955152 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -47,7 +47,7 @@ use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; use uucore::{fs::display_permissions, version_cmp::version_cmp}; fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", execution_phrase!()) + format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase()) } pub mod options { @@ -618,7 +618,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about( "By default, ls will list the files and contents of any directories on \ diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 046628f3a..848f79988 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -23,7 +23,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]... [USER]", execution_phrase!()) + format!("{0} [OPTION]... [USER]", uucore::execution_phrase()) } #[uucore_procs::gen_uumain] @@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( @@ -103,7 +103,11 @@ fn mkdir(path: &Path, recursive: bool, mode: u16, verbose: bool) -> UResult<()> create_dir(path).map_err_context(|| format!("cannot create directory '{}'", path.display()))?; if verbose { - println!("{}: created directory '{}'", util_name!(), path.display()); + println!( + "{}: created directory '{}'", + uucore::util_name(), + path.display() + ); } chmod(path, mode) diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 10ea8337c..009675811 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 1a52de14f..f8fb9c469 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -71,8 +71,8 @@ fn _mknod(file_name: &str, mode: mode_t, dev: dev_t) -> i32 { } if errno == -1 { - let c_str = - CString::new(execution_phrase!().as_bytes()).expect("Failed to convert to CString"); + let c_str = CString::new(uucore::execution_phrase().as_bytes()) + .expect("Failed to convert to CString"); // shows the error from the mknod syscall libc::perror(c_str.as_ptr()); } @@ -113,7 +113,10 @@ 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.", execution_phrase!()); + eprintln!( + "Try '{} --help' for more information.", + uucore::execution_phrase() + ); 1 } else { _mknod(file_name, S_IFIFO | mode, 0) @@ -122,7 +125,10 @@ 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.", execution_phrase!()); + eprintln!( + "Try '{} --help' for more information.", + uucore::execution_phrase() + ); 1 } (Some(major), Some(minor)) => { @@ -145,7 +151,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .usage(USAGE) .after_help(LONG_HELP) diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 2d42d38ba..0b30f0087 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -37,7 +37,7 @@ static OPT_T: &str = "t"; static ARG_TEMPLATE: &str = "template"; fn usage() -> String { - format!("{0} [OPTION]... [TEMPLATE]", execution_phrase!()) + format!("{0} [OPTION]... [TEMPLATE]", uucore::execution_phrase()) } #[derive(Debug)] @@ -134,7 +134,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index ee03c0d8a..8097d1402 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -93,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .about("A file perusal filter for CRT viewing.") .version(crate_version!()) .arg( diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 1cf45c36a..5f825113b 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -63,7 +63,7 @@ fn usage() -> String { "{0} [OPTION]... [-T] SOURCE DEST {0} [OPTION]... SOURCE... DIRECTORY {0} [OPTION]... -t DIRECTORY SOURCE...", - execution_phrase!() + uucore::execution_phrase() ) } @@ -133,7 +133,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( @@ -296,7 +296,7 @@ fn exec(files: &[PathBuf], b: Behavior) -> i32 { "mv: extra operand '{}'\n\ Try '{} --help' for more information.", files[2].display(), - execution_phrase!() + uucore::execution_phrase() ); return 1; } @@ -353,7 +353,7 @@ fn rename(from: &Path, to: &Path, b: &Behavior) -> io::Result<()> { match b.overwrite { OverwriteMode::NoClobber => return Ok(()), OverwriteMode::Interactive => { - println!("{}: overwrite '{}'? ", util_name!(), to.display()); + println!("{}: overwrite '{}'? ", uucore::util_name(), to.display()); if !read_yes() { return Ok(()); } diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index a93137c10..fbc2be0e5 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -31,7 +31,7 @@ Run COMMAND with an adjusted niceness, which affects process scheduling. With no COMMAND, print the current niceness. Niceness values range from at least -20 (most favorable to the process) to 19 (least favorable to the process).", - execution_phrase!() + uucore::execution_phrase() ) } @@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if !matches.is_present(options::COMMAND) { show_error!( "A command must be given with an adjustment.\nTry '{} --help' for more information.", - execution_phrase!() + uucore::execution_phrase() ); return 125; } @@ -101,7 +101,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .setting(AppSettings::TrailingVarArg) .version(crate_version!()) .arg( diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index d5ea18f8a..600ebace0 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -143,7 +143,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 17b06301f..1ecb9914f 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -71,7 +71,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) @@ -157,7 +157,10 @@ fn find_stdout() -> File { } fn usage() -> String { - format!("{0} COMMAND [ARG]...\n {0} FLAG", execution_phrase!()) + format!( + "{0} COMMAND [ARG]...\n {0} FLAG", + uucore::execution_phrase() + ) } #[cfg(target_vendor = "apple")] diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index c10d79d40..16b8d8c3a 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -28,7 +28,7 @@ static OPT_IGNORE: &str = "ignore"; static ABOUT: &str = "Print the number of cores available to the current process."; fn usage() -> String { - format!("{0} [OPTIONS]...", execution_phrase!()) + format!("{0} [OPTIONS]...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 849abeb71..1798975dc 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -51,7 +51,7 @@ Multiple fields/ranges can be separated with commas "; fn usage() -> String { - format!("{0} [OPTION]... [NUMBER]...", execution_phrase!()) + format!("{0} [OPTION]... [NUMBER]...", uucore::execution_phrase()) } fn handle_args<'a>(args: impl Iterator, options: NumfmtOptions) -> Result<()> { @@ -175,7 +175,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/od/src/multifilereader.rs b/src/uu/od/src/multifilereader.rs index 303093b01..2f44da803 100644 --- a/src/uu/od/src/multifilereader.rs +++ b/src/uu/od/src/multifilereader.rs @@ -57,7 +57,7 @@ impl<'b> MultifileReader<'b> { // print an error at the time that the file is needed, // then move on the the next file. // This matches the behavior of the original `od` - eprintln!("{}: '{}': {}", util_name!(), fname, e); + eprintln!("{}: '{}': {}", uucore::util_name(), fname, e); self.any_err = true } } @@ -90,7 +90,7 @@ impl<'b> io::Read for MultifileReader<'b> { Ok(0) => break, Ok(n) => n, Err(e) => { - eprintln!("{}: I/O: {}", util_name!(), e); + eprintln!("{}: I/O: {}", uucore::util_name(), e); self.any_err = true; break; } diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index b37990fd5..6c1110362 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -252,7 +252,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> clap::App<'static, 'static> { - clap::App::new(util_name!()) + clap::App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .usage(USAGE) diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 801de50dc..9ac5507df 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -52,7 +52,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index c1ea76bf9..863bb6bf2 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -39,7 +39,7 @@ const POSIX_PATH_MAX: usize = 256; const POSIX_NAME_MAX: usize = 14; fn usage() -> String { - format!("{0} [OPTION]... NAME...", execution_phrase!()) + format!("{0} [OPTION]... NAME...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let mut res = if paths.is_none() { show_error!( "missing operand\nTry '{} --help' for more information", - execution_phrase!() + uucore::execution_phrase() ); false } else { @@ -98,7 +98,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 9268ffd2b..02573c994 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -41,7 +41,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]... [USER]...", execution_phrase!()) + format!("{0} [OPTION]... [USER]...", uucore::execution_phrase()) } fn get_long_usage() -> String { @@ -130,7 +130,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 9ee5158ec..1358cef6c 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -23,7 +23,6 @@ use std::fs::{metadata, File}; use std::io::{stdin, stdout, BufRead, BufReader, Lines, Read, Stdout, Write}; #[cfg(unix)] use std::os::unix::fs::FileTypeExt; -use uucore::util_name; type IOError = std::io::Error; @@ -170,7 +169,7 @@ quick_error! { pub fn uu_app() -> clap::App<'static, 'static> { // TODO: migrate to clap to get more shell completions - clap::App::new(util_name!()) + clap::App::new(uucore::util_name()) } pub fn uumain(args: impl uucore::Args) -> i32 { diff --git a/src/uu/printenv/src/printenv.rs b/src/uu/printenv/src/printenv.rs index da46f7667..5d32cfbcc 100644 --- a/src/uu/printenv/src/printenv.rs +++ b/src/uu/printenv/src/printenv.rs @@ -7,9 +7,6 @@ /* last synced with: printenv (GNU coreutils) 8.13 */ -#[macro_use] -extern crate uucore; - use clap::{crate_version, App, Arg}; use std::env; @@ -20,7 +17,7 @@ static OPT_NULL: &str = "null"; static ARG_VARIABLES: &str = "variables"; fn usage() -> String { - format!("{0} [VARIABLE]... [OPTION]...", execution_phrase!()) + format!("{0} [VARIABLE]... [OPTION]...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -55,7 +52,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index 22e02ffe2..d3c8dca90 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -2,9 +2,6 @@ // spell-checker:ignore (change!) each's // spell-checker:ignore (ToDO) LONGHELP FORMATSTRING templating parameterizing formatstr -#[macro_use] -extern crate uucore; - use clap::{crate_version, App, Arg}; use uucore::InvalidEncodingHandling; @@ -284,8 +281,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if args.len() <= 1 { println!( "{0}: missing operand\nTry '{1} --help' for more information.", - util_name!(), - execution_phrase!() + uucore::util_name(), + uucore::execution_phrase() ); return 1; } @@ -294,7 +291,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if formatstr == "--help" { print!("{} {}", LONGHELP_LEAD, LONGHELP_BODY); } else if formatstr == "--version" { - println!("{} {}", util_name!(), crate_version!()); + println!("{} {}", uucore::util_name(), crate_version!()); } else { let printf_args = &args[2..]; memo::Memo::run_all(formatstr, printf_args); @@ -303,7 +300,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .arg(Arg::with_name(VERSION).long(VERSION)) .arg(Arg::with_name(HELP).long(HELP)) } diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 4f16af470..264a37d72 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -659,7 +659,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(BRIEF) diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index 388a10463..75dc637e6 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -35,7 +35,7 @@ pub fn absolute_path(path: &Path) -> io::Result { } fn usage() -> String { - format!("{0} [OPTION]... FILE...", execution_phrase!()) + format!("{0} [OPTION]... FILE...", uucore::execution_phrase()) } #[uucore_procs::gen_uumain] @@ -66,7 +66,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index 81d8376f6..aab368af1 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -29,7 +29,7 @@ const OPT_ZERO: &str = "zero"; const ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", execution_phrase!()) + format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -59,14 +59,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "missing operand\nTry '{} --help' for more information", - execution_phrase!() + uucore::execution_phrase() ); } if no_newline && files.len() > 1 && !silent { eprintln!( "{}: ignoring --no-newline with multiple arguments", - util_name!() + uucore::util_name() ); no_newline = false; } @@ -80,7 +80,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if verbose { eprintln!( "{}: {}: errno {}", - util_name!(), + uucore::util_name(), f, err.raw_os_error().unwrap() ); @@ -95,7 +95,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if verbose { eprintln!( "{}: {}: errno {:?}", - util_name!(), + uucore::util_name(), f, err.raw_os_error().unwrap() ); @@ -110,7 +110,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index 7ce8fc179..b12fef3d9 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -23,7 +23,7 @@ static OPT_ZERO: &str = "zero"; static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [OPTION]... FILE...", execution_phrase!()) + format!("{0} [OPTION]... FILE...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -55,7 +55,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/relpath/src/relpath.rs b/src/uu/relpath/src/relpath.rs index 941a6a3f2..1878e2efa 100644 --- a/src/uu/relpath/src/relpath.rs +++ b/src/uu/relpath/src/relpath.rs @@ -7,9 +7,6 @@ // spell-checker:ignore (ToDO) subpath absto absfrom absbase -#[macro_use] -extern crate uucore; - use clap::{crate_version, App, Arg}; use std::env; use std::path::{Path, PathBuf}; @@ -26,7 +23,7 @@ mod options { } fn usage() -> String { - format!("{} [-d DIR] TO [FROM]", execution_phrase!()) + format!("{} [-d DIR] TO [FROM]", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -82,7 +79,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 03977bc3e..0613ff857 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -53,7 +53,7 @@ static OPT_VERBOSE: &str = "verbose"; static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [OPTION]... FILE...", execution_phrase!()) + format!("{0} [OPTION]... FILE...", uucore::execution_phrase()) } fn get_long_usage() -> String { @@ -93,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { // Still check by hand and not use clap // Because "rm -f" is a thing show_error!("missing an argument"); - show_error!("for help, try '{0} --help'", execution_phrase!()); + show_error!("for help, try '{0} --help'", uucore::execution_phrase()); return 1; } else { let options = Options { @@ -140,7 +140,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index 135350a8e..cafd8e982 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -27,7 +27,7 @@ static ENOTDIR: i32 = 20; static ENOTDIR: i32 = 267; fn usage() -> String { - format!("{0} [OPTION]... DIRECTORY...", execution_phrase!()) + format!("{0} [OPTION]... DIRECTORY...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -53,7 +53,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index db5537b8b..05388e7a1 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -27,7 +27,7 @@ fn usage() -> String { "{0} [OPTION]... LAST {0} [OPTION]... FIRST LAST {0} [OPTION]... FIRST INCREMENT LAST", - execution_phrase!() + uucore::execution_phrase() ) } #[derive(Clone)] @@ -72,13 +72,13 @@ impl FromStr for Number { Ok(value) if value.is_nan() => Err(format!( "invalid 'not-a-number' argument: '{}'\nTry '{} --help' for more information.", s, - execution_phrase!(), + uucore::execution_phrase(), )), Ok(value) => Ok(Number::F64(value)), Err(_) => Err(format!( "invalid floating point argument: '{}'\nTry '{} --help' for more information.", s, - execution_phrase!(), + uucore::execution_phrase(), )), }, } @@ -123,7 +123,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { show_error!( "invalid Zero increment value: '{}'\nTry '{} --help' for more information.", numbers[1], - execution_phrase!() + uucore::execution_phrase() ); return 1; } @@ -163,7 +163,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .setting(AppSettings::AllowLeadingHyphen) .version(crate_version!()) .about(ABOUT) diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 521cb8dc6..25cf704bf 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -214,7 +214,7 @@ for even very expensive hardware probing to recover the data. "; fn usage() -> String { - format!("{} [OPTION]... FILE...", execution_phrase!()) + format!("{} [OPTION]... FILE...", uucore::execution_phrase()) } static AFTER_HELP: &str = @@ -330,7 +330,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(AFTER_HELP) diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 7f69a5fe9..a193b702b 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -115,7 +115,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .template(TEMPLATE) diff --git a/src/uu/sleep/src/sleep.rs b/src/uu/sleep/src/sleep.rs index 136d92e4d..a70a524c4 100644 --- a/src/uu/sleep/src/sleep.rs +++ b/src/uu/sleep/src/sleep.rs @@ -29,7 +29,7 @@ mod options { fn usage() -> String { format!( "{0} {1}[SUFFIX]... \n {0} OPTION", - execution_phrase!(), + uucore::execution_phrase(), options::NUMBER ) } @@ -49,7 +49,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 049be5352..9aae23bb8 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1060,7 +1060,7 @@ fn usage() -> String { Write the sorted concatenation of all FILE(s) to standard output. Mandatory arguments for long options are mandatory for short options too. With no FILE, or when FILE is -, read standard input.", - execution_phrase!() + uucore::execution_phrase() ) } @@ -1286,7 +1286,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index ce21361af..070df81f6 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -35,7 +35,10 @@ static ARG_INPUT: &str = "input"; static ARG_PREFIX: &str = "prefix"; fn usage() -> String { - format!("{0} [OPTION]... [INPUT [PREFIX]]", execution_phrase!()) + format!( + "{0} [OPTION]... [INPUT [PREFIX]]", + uucore::execution_phrase() + ) } fn get_long_usage() -> String { format!( @@ -125,7 +128,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about("Create output files containing consecutive or interleaved sections of input") // strategy (mutually exclusive) diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index d3783d725..d017999b4 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -883,7 +883,7 @@ impl Stater { } fn usage() -> String { - format!("{0} [OPTION]... FILE...", execution_phrase!()) + format!("{0} [OPTION]... FILE...", uucore::execution_phrase()) } fn get_long_usage() -> String { @@ -963,7 +963,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index a16a40ce5..e87b3a225 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -48,7 +48,7 @@ mod options { } fn usage() -> String { - format!("{0} OPTION... COMMAND", execution_phrase!()) + format!("{0} OPTION... COMMAND", uucore::execution_phrase()) } const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.so")); @@ -161,7 +161,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { 125, "{}\nTry '{} --help' for more information.", e.0, - execution_phrase!() + uucore::execution_phrase() ) }); @@ -191,7 +191,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index b4b2294aa..f1147ca2e 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -140,7 +140,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 7dd37d780..f49f51728 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -160,7 +160,7 @@ mod platform { } fn usage() -> String { - format!("{0} [OPTION]... FILE...", execution_phrase!()) + format!("{0} [OPTION]... FILE...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -193,7 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 70fa04622..67b361a76 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 106c1c5db..44f910ea0 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about("output the last part of files") // TODO: add usage diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 461600003..d98835265 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -33,7 +33,7 @@ struct Options { } fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", execution_phrase!()) + format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -57,7 +57,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help("If a FILE is -, it refers to a file named - .") diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index 939e13ab9..6eea00080 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -14,7 +14,6 @@ use clap::{crate_version, App, AppSettings}; use parser::{parse, Symbol}; use std::ffi::{OsStr, OsString}; use std::path::Path; -use uucore::util_name; const USAGE: &str = "test EXPRESSION or: test @@ -87,7 +86,7 @@ the version described here. Please refer to your shell's documentation for details about the options it supports."; pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .setting(AppSettings::DisableHelpFlags) .setting(AppSettings::DisableVersion) } diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index 8b169b5b5..89fde82ca 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -23,7 +23,10 @@ use uucore::InvalidEncodingHandling; static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION."; fn usage() -> String { - format!("{0} [OPTION] DURATION COMMAND...", execution_phrase!()) + format!( + "{0} [OPTION] DURATION COMMAND...", + uucore::execution_phrase() + ) } const ERR_EXIT_STATUS: i32 = 125; diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 8ddfcfa74..7c0903665 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -48,7 +48,7 @@ fn local_tm_to_filetime(tm: time::Tm) -> FileTime { } fn usage() -> String { - format!("{0} [OPTION]... [USER]", execution_phrase!()) + format!("{0} [OPTION]... [USER]", uucore::execution_phrase()) } #[uucore_procs::gen_uumain] @@ -129,7 +129,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 7b6fbd6f2..d46318e38 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -229,7 +229,7 @@ fn translate_input( } fn usage() -> String { - format!("{} [OPTION]... SET1 [SET2]", execution_phrase!()) + format!("{} [OPTION]... SET1 [SET2]", uucore::execution_phrase()) } fn get_long_usage() -> String { @@ -264,7 +264,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if sets.is_empty() { show_error!( "missing operand\nTry '{} --help' for more information.", - execution_phrase!() + uucore::execution_phrase() ); return 1; } @@ -273,7 +273,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { show_error!( "missing operand after '{}'\nTry '{} --help' for more information.", sets[0], - execution_phrase!() + uucore::execution_phrase() ); return 1; } @@ -312,7 +312,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index 07e075175..6b4a87bf1 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -10,7 +10,6 @@ extern crate uucore; use clap::App; use uucore::error::UResult; -use uucore::util_name; #[uucore_procs::gen_uumain] pub fn uumain(args: impl uucore::Args) -> UResult<()> { @@ -19,5 +18,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) } diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index fdcff3fd5..062ef3811 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -64,7 +64,7 @@ pub mod options { } fn usage() -> String { - format!("{0} [OPTION]... [FILE]...", execution_phrase!()) + format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase()) } fn get_long_usage() -> String { @@ -133,7 +133,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index c2416afb4..c0ef66598 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -90,7 +90,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .usage(USAGE) .about(SUMMARY) diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 284916050..94e2e6b24 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -9,9 +9,6 @@ // spell-checker:ignore (ToDO) ttyname filedesc -#[macro_use] -extern crate uucore; - use clap::{crate_version, App, Arg}; use std::ffi::CStr; use std::io::Write; @@ -24,7 +21,7 @@ mod options { } fn usage() -> String { - format!("{0} [OPTION]...", execution_phrase!()) + format!("{0} [OPTION]...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -78,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index b15d950bf..5f8dfd8a8 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -50,7 +50,7 @@ const HOST_OS: &str = "Fuchsia"; const HOST_OS: &str = "Redox"; pub fn uumain(args: impl uucore::Args) -> i32 { - let usage = format!("{} [OPTION]...", execution_phrase!()); + let usage = format!("{} [OPTION]...", uucore::execution_phrase()); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let uname = return_if_err!(1, PlatformInfo::new()); @@ -119,7 +119,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg(Arg::with_name(options::ALL) diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 4a4c50feb..cb8541048 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -102,7 +102,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .name(NAME) .version(crate_version!()) .usage(USAGE) diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 10cb7a4ce..5c3fa3b1e 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -222,7 +222,10 @@ fn opt_parsed(opt_name: &str, matches: &ArgMatches) -> Option { } fn usage() -> String { - format!("{0} [OPTION]... [INPUT [OUTPUT]]...", execution_phrase!()) + format!( + "{0} [OPTION]... [INPUT [OUTPUT]]...", + uucore::execution_phrase() + ) } fn get_long_usage() -> String { @@ -281,7 +284,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index e0a743c1c..c7fc00639 100644 --- a/src/uu/unlink/src/unlink.rs +++ b/src/uu/unlink/src/unlink.rs @@ -23,7 +23,7 @@ static ABOUT: &str = "Unlink the file at [FILE]."; static OPT_PATH: &str = "FILE"; fn usage() -> String { - format!("{} [OPTION]... FILE", execution_phrase!()) + format!("{} [OPTION]... FILE", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -44,13 +44,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 { crash!( 1, "missing operand\nTry '{0} --help' for more information.", - execution_phrase!() + uucore::execution_phrase() ); } else if paths.len() > 1 { crash!( 1, "extra operand: '{1}'\nTry '{0} --help' for more information.", - execution_phrase!(), + uucore::execution_phrase(), paths[1] ); } @@ -95,7 +95,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg(Arg::with_name(OPT_PATH).hidden(true).multiple(true)) diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index b19566ec3..e58f398db 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -33,7 +33,7 @@ extern "C" { } fn usage() -> String { - format!("{0} [OPTION]...", execution_phrase!()) + format!("{0} [OPTION]...", uucore::execution_phrase()) } pub fn uumain(args: impl uucore::Args) -> i32 { @@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index 7aed00507..866093189 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -8,9 +8,6 @@ // spell-checker:ignore (paths) wtmp -#[macro_use] -extern crate uucore; - use clap::{crate_version, App, Arg}; use uucore::utmpx::{self, Utmpx}; @@ -19,7 +16,7 @@ static ABOUT: &str = "Print the user names of users currently logged in to the c static ARG_FILES: &str = "files"; fn usage() -> String { - format!("{0} [FILE]", execution_phrase!()) + format!("{0} [FILE]", uucore::execution_phrase()) } fn get_long_usage() -> String { @@ -65,7 +62,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg(Arg::with_name(ARG_FILES).takes_value(true).max_values(1)) diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 3077d31d9..ff586a6f6 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -99,7 +99,7 @@ fn usage() -> String { format!( "{0} [OPTION]... [FILE]... With no FILE, or when FILE is -, read standard input.", - execution_phrase!() + uucore::execution_phrase() ) } @@ -164,7 +164,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 59e8b7c36..b0ef7b3fa 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -45,7 +45,10 @@ static RUNLEVEL_HELP: &str = "print current runlevel"; static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)"; fn usage() -> String { - format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", execution_phrase!()) + format!( + "{0} [OPTION]... [ FILE | ARG1 ARG2 ]", + uucore::execution_phrase() + ) } fn get_long_usage() -> String { @@ -160,7 +163,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } pub fn uu_app() -> App<'static, 'static> { - App::new(util_name!()) + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 8920b226d..6acd4e017 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -87,6 +87,38 @@ pub fn set_utility_is_second_arg() { crate::macros::UTILITY_IS_SECOND_ARG.store(true, Ordering::SeqCst) } +/// Get the executable path (as `OsString`). +fn executable_os() -> OsString { + args_os().next().unwrap() +} + +/// Get the executable path (as `String`). +fn executable() -> String { + executable_os().to_string_lossy().into_owned() +} + +/// Derive the utility name. +pub fn util_name() -> String { + if get_utility_is_second_arg() { + args_os().nth(1).unwrap().to_string_lossy().into_owned() + } else { + executable() + } +} + +/// Derive the complete execution phrase for "usage". +pub fn execution_phrase() -> String { + if get_utility_is_second_arg() { + args_os() + .take(2) + .map(|os_str| os_str.to_string_lossy().into_owned()) + .collect::>() + .join(" ") + } else { + executable() + } +} + pub enum InvalidEncodingHandling { Ignore, ConvertLossy, diff --git a/src/uucore/src/lib/macros.rs b/src/uucore/src/lib/macros.rs index c9fff455a..d16f04504 100644 --- a/src/uucore/src/lib/macros.rs +++ b/src/uucore/src/lib/macros.rs @@ -10,67 +10,14 @@ use std::sync::atomic::AtomicBool; /// Whether we were called as a multicall binary ("coreutils ") pub static UTILITY_IS_SECOND_ARG: AtomicBool = AtomicBool::new(false); -/// Get the executable path (as `OsString`). -#[macro_export] -macro_rules! executable_os( - () => ({ - $crate::args_os().next().unwrap() - }) -); - -/// Get the executable path (as `String`). -#[macro_export] -#[deprecated = "Use util_name!() or execution_phrase!() instead"] -macro_rules! executable( - () => ({ - $crate::executable_os!().to_string_lossy().to_string() - }) -); - -/// Derive the utility name. -#[macro_export] -macro_rules! util_name( - () => ({ - if $crate::get_utility_is_second_arg() { - $crate::args_os().nth(1).unwrap().to_string_lossy().to_string() - } else { - #[allow(deprecated)] - { - $crate::executable!() - } - } - }) -); - -//==== - -/// Derive the complete execution phrase for "usage". -#[macro_export] -macro_rules! execution_phrase( - () => ({ - if $crate::get_utility_is_second_arg() { - $crate::args_os() - .take(2) - .map(|os_str| os_str.to_string_lossy().to_string()) - .collect::>() - .join(" ") - } else { - #[allow(deprecated)] - { - $crate::executable!() - } - } - }) -); - //==== #[macro_export] macro_rules! show( ($err:expr) => ({ let e = $err; - uucore::error::set_exit_code(e.code()); - eprintln!("{}: {}", $crate::util_name!(), e); + $crate::error::set_exit_code(e.code()); + eprintln!("{}: {}", $crate::util_name(), e); }) ); @@ -87,7 +34,7 @@ macro_rules! show_if_err( #[macro_export] macro_rules! show_error( ($($args:tt)+) => ({ - eprint!("{}: ", $crate::util_name!()); + eprint!("{}: ", $crate::util_name()); eprintln!($($args)+); }) ); @@ -96,7 +43,7 @@ macro_rules! show_error( #[macro_export] macro_rules! show_error_custom_description ( ($err:expr,$($args:tt)+) => ({ - eprint!("{}: {}: ", $crate::util_name!(), $err); + eprint!("{}: {}: ", $crate::util_name(), $err); eprintln!($($args)+); }) ); @@ -104,7 +51,7 @@ macro_rules! show_error_custom_description ( #[macro_export] macro_rules! show_warning( ($($args:tt)+) => ({ - eprint!("{}: warning: ", $crate::util_name!()); + eprint!("{}: warning: ", $crate::util_name()); eprintln!($($args)+); }) ); @@ -113,9 +60,9 @@ macro_rules! show_warning( #[macro_export] macro_rules! show_usage_error( ($($args:tt)+) => ({ - eprint!("{}: ", $crate::util_name!()); + eprint!("{}: ", $crate::util_name()); eprintln!($($args)+); - eprintln!("Try '{} --help' for more information.", $crate::execution_phrase!()); + eprintln!("Try '{} --help' for more information.", $crate::execution_phrase()); }) ); diff --git a/src/uucore/src/lib/mods/coreopts.rs b/src/uucore/src/lib/mods/coreopts.rs index b81ef7e5a..b534ff902 100644 --- a/src/uucore/src/lib/mods/coreopts.rs +++ b/src/uucore/src/lib/mods/coreopts.rs @@ -120,7 +120,7 @@ impl<'a> CoreOptions<'a> { macro_rules! app { ($syntax: expr, $summary: expr, $long_help: expr) => { uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText { - name: util_name!(), + name: uucore::util_name(), version: env!("CARGO_PKG_VERSION"), syntax: $syntax, summary: $summary, @@ -130,7 +130,7 @@ macro_rules! app { }; ($syntax: expr, $summary: expr, $long_help: expr, $display_usage: expr) => { uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText { - name: util_name!(), + name: uucore::util_name(), version: env!("CARGO_PKG_VERSION"), syntax: $syntax, summary: $summary, diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index 7f7460283..092a4a66c 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.", execution_phrase!()); + eprintln!("Try '{} --help' for more information.", uucore::execution_phrase()); } e.code() } From a9bab842ecb06ba03df3bcb16f93b6db6d994187 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 19 Aug 2021 12:41:14 +0200 Subject: [PATCH 23/25] Use grcov latest again (grcov 0.8.2 fixed the take issue) --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 90b836c0f..8a1e142df 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -625,7 +625,7 @@ jobs: uses: actions-rs/install@v0.1 with: crate: grcov - version: 0.8.0 + version: latest use-tool-cache: false - name: Generate coverage data (via `grcov`) id: coverage From 1eb7193ee89d031d5dd8538ceedcdc1106af14f5 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Tue, 17 Aug 2021 15:42:31 +0200 Subject: [PATCH 24/25] wc: fix clippy lint --- src/uu/wc/src/wc.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index ff586a6f6..d77cd6b4b 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -350,13 +350,8 @@ fn digit_width(input: &Input) -> WcResult> { fn max_width(inputs: &[Input]) -> usize { let mut result = 1; for input in inputs { - match digit_width(input) { - Ok(maybe_n) => { - if let Some(n) = maybe_n { - result = result.max(n); - } - } - Err(_) => continue, + if let Ok(Some(n)) = digit_width(input) { + result = result.max(n); } } result From 0062e54b5ed7a3fecfb760c306f8be4a77583e60 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Fri, 20 Aug 2021 00:20:56 +0200 Subject: [PATCH 25/25] test_util_name: symlink the xecutable instead of copying Speculative fix for "text file busy" errors. --- tests/test_util_name.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index 640fecd44..b0a78a2e8 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -2,6 +2,11 @@ mod common; use common::util::TestScenario; +#[cfg(unix)] +use std::os::unix::fs::symlink as symlink_file; +#[cfg(windows)] +use std::os::windows::fs::symlink_file; + #[test] #[cfg(feature = "ls")] fn execution_phrase_double() { @@ -24,7 +29,7 @@ fn execution_phrase_single() { use std::process::Command; let scenario = TestScenario::new("ls"); - std::fs::copy(scenario.bin_path, scenario.fixtures.plus("uu-ls")).unwrap(); + symlink_file(scenario.bin_path, scenario.fixtures.plus("uu-ls")).unwrap(); let output = Command::new(scenario.fixtures.plus("uu-ls")) .arg("--some-invalid-arg") .output() @@ -65,7 +70,7 @@ fn util_name_single() { }; let scenario = TestScenario::new("sort"); - std::fs::copy(scenario.bin_path, scenario.fixtures.plus("uu-sort")).unwrap(); + symlink_file(scenario.bin_path, scenario.fixtures.plus("uu-sort")).unwrap(); let mut child = Command::new(scenario.fixtures.plus("uu-sort")) .stdin(Stdio::piped()) .stderr(Stdio::piped())