1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

refactor ~ use execution_phrase!() for usage messaging

This commit is contained in:
Roy Ivy III 2021-07-26 22:54:48 -05:00 committed by Michael Debertol
parent 318f366ace
commit c0854000d1
68 changed files with 119 additions and 121 deletions

View file

@ -29,13 +29,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
static BASE_CMD_PARSE_ERROR: i32 = 1; static BASE_CMD_PARSE_ERROR: i32 = 1;
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]", executable!()) format!("{0} [OPTION]... [FILE]", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let format = Format::Base32; let format = Format::Base32;
let usage = usage(); let usage = usage();
let name = executable!(); let name = util_name!();
let config_result: Result<base_common::Config, String> = let config_result: Result<base_common::Config, String> =
base_common::parse_base_cmd_args(args, name, VERSION, ABOUT, &usage); 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> { pub fn uu_app() -> App<'static, 'static> {
base_common::base_app(executable!(), VERSION, ABOUT) base_common::base_app(util_name!(), VERSION, ABOUT)
} }

View file

@ -30,13 +30,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
static BASE_CMD_PARSE_ERROR: i32 = 1; static BASE_CMD_PARSE_ERROR: i32 = 1;
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]", executable!()) format!("{0} [OPTION]... [FILE]", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let format = Format::Base64; let format = Format::Base64;
let usage = usage(); let usage = usage();
let name = executable!(); let name = util_name!();
let config_result: Result<base_common::Config, String> = let config_result: Result<base_common::Config, String> =
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)); let config = config_result.unwrap_or_else(|s| crash!(BASE_CMD_PARSE_ERROR, "{}", s));

View file

@ -21,7 +21,7 @@ fn usage() -> String {
format!( format!(
"{0} NAME [SUFFIX] "{0} NAME [SUFFIX]
{0} OPTION... NAME...", {0} OPTION... NAME...",
executable!() execution_phrase!()
) )
} }
@ -47,7 +47,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
crash!( crash!(
1, 1,
"{1}\nTry `{0} --help` for more information.", "{1}\nTry `{0} --help` for more information.",
executable!(), execution_phrase!(),
"missing operand" "missing operand"
); );
} }
@ -61,7 +61,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
crash!( crash!(
1, 1,
"extra operand '{1}'\nTry `{0} --help` for more information.", "extra operand '{1}'\nTry `{0} --help` for more information.",
executable!(), execution_phrase!(),
matches.values_of(options::NAME).unwrap().nth(2).unwrap() matches.values_of(options::NAME).unwrap().nth(2).unwrap()
); );
} }

View file

@ -62,7 +62,7 @@ const FTS_LOGICAL: u8 = 1 << 2;
fn usage() -> String { fn usage() -> String {
format!( format!(
"{0} [OPTION]... GROUP FILE...\n {0} [OPTION]... --reference=RFILE FILE...", "{0} [OPTION]... GROUP FILE...\n {0} [OPTION]... --reference=RFILE FILE...",
executable!() execution_phrase!()
) )
} }

View file

@ -41,7 +41,7 @@ fn usage() -> String {
"{0} [OPTION]... MODE[,MODE]... FILE... "{0} [OPTION]... MODE[,MODE]... FILE...
or: {0} [OPTION]... OCTAL-MODE FILE... or: {0} [OPTION]... OCTAL-MODE FILE...
or: {0} [OPTION]... --reference=RFILE FILE...", or: {0} [OPTION]... --reference=RFILE FILE...",
executable!() execution_phrase!()
) )
} }

View file

@ -64,7 +64,7 @@ const FTS_LOGICAL: u8 = 1 << 2;
fn usage() -> String { fn usage() -> String {
format!( format!(
"{0} [OPTION]... [OWNER][:[GROUP]] FILE...\n{0} [OPTION]... --reference=RFILE FILE...", "{0} [OPTION]... [OWNER][:[GROUP]] FILE...\n{0} [OPTION]... --reference=RFILE FILE...",
executable!() execution_phrase!()
) )
} }

View file

@ -16,9 +16,8 @@ use std::io::Error;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use uucore::libc::{self, chroot, setgid, setgroups, setuid}; 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 ABOUT: &str = "Run COMMAND with root directory set to NEWROOT.";
static SYNTAX: &str = "[OPTION]... NEWROOT [COMMAND [ARG]...]"; static SYNTAX: &str = "[OPTION]... NEWROOT [COMMAND [ARG]...]";
@ -47,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
None => crash!( None => crash!(
1, 1,
"Missing operand: NEWROOT\nTry `{} --help` for more information.", "Missing operand: NEWROOT\nTry `{} --help` for more information.",
NAME execution_phrase!()
), ),
}; };

View file

@ -32,7 +32,7 @@ mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{} [OPTION]... FILE1 FILE2", executable!()) format!("{} [OPTION]... FILE1 FILE2", execution_phrase!())
} }
fn mkdelim(col: usize, opts: &ArgMatches) -> String { fn mkdelim(col: usize, opts: &ArgMatches) -> String {

View file

@ -99,7 +99,7 @@ quick_error! {
NotImplemented(opt: String) { display("Option '{}' not yet implemented.", opt) } NotImplemented(opt: String) { display("Option '{}' not yet implemented.", opt) }
/// Invalid arguments to backup /// Invalid arguments to backup
Backup(description: String) { display("{}\nTry `{} --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]... [-T] SOURCE DEST
{0} [OPTION]... SOURCE... DIRECTORY {0} [OPTION]... SOURCE... DIRECTORY
{0} [OPTION]... -t DIRECTORY SOURCE...", {0} [OPTION]... -t DIRECTORY SOURCE...",
executable!() execution_phrase!()
) )
} }
@ -1060,7 +1060,7 @@ impl OverwriteMode {
match *self { match *self {
OverwriteMode::NoClobber => Err(Error::NotAllFilesCopied), OverwriteMode::NoClobber => Err(Error::NotAllFilesCopied),
OverwriteMode::Interactive(_) => { OverwriteMode::Interactive(_) => {
if prompt_yes!("{}: overwrite {}? ", executable!(), path.display()) { if prompt_yes!("{}: overwrite {}? ", util_name!(), path.display()) {
Ok(()) Ok(())
} else { } else {
Err(Error::Skipped(format!( Err(Error::Skipped(format!(

View file

@ -35,7 +35,7 @@ mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE PATTERN...", executable!()) format!("{0} [OPTION]... FILE PATTERN...", execution_phrase!())
} }
/// Command line options for csplit. /// Command line options for csplit.

View file

@ -80,7 +80,7 @@ struct Filesystem {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", execution_phrase!())
} }
impl FsSelector { impl FsSelector {
@ -295,7 +295,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
#[cfg(windows)] #[cfg(windows)]
{ {
if matches.is_present(OPT_INODES) { if matches.is_present(OPT_INODES) {
println!("{}: doesn't support -i option", executable!()); println!("{}: doesn't support -i option", util_name!());
return Ok(()); return Ok(());
} }
} }

View file

@ -63,7 +63,7 @@ pub fn guess_syntax() -> OutputFmt {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} {1}", executable!(), SYNTAX) format!("{0} {1}", execution_phrase!(), SYNTAX)
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -21,7 +21,7 @@ mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION] NAME...", executable!()) format!("{0} [OPTION] NAME...", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {

View file

@ -396,7 +396,7 @@ fn usage() -> String {
format!( format!(
"{0} [OPTION]... [FILE]... "{0} [OPTION]... [FILE]...
{0} [OPTION]... --files0-from=F", {0} [OPTION]... --files0-from=F",
executable!() execution_phrase!()
) )
} }
@ -424,7 +424,7 @@ Valid arguments are:
- 'iso' - 'iso'
Try `{} --help` for more information.", Try `{} --help` for more information.",
s, s,
executable!() execution_phrase!()
), ),
DuError::InvalidTimeArg(s) => write!( DuError::InvalidTimeArg(s) => write!(
f, f,

View file

@ -33,7 +33,7 @@ static LONG_HELP: &str = "";
static DEFAULT_TABSTOP: usize = 8; static DEFAULT_TABSTOP: usize = 8;
fn usage() -> String { 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 /// The mode to use when replacing tabs beyond the last one specified in

View file

@ -140,5 +140,5 @@ Environment variables:
} }
fn print_version() { fn print_version() {
println!("{} {}", executable!(), crate_version!()); println!("{} {}", util_name!(), crate_version!());
} }

View file

@ -51,7 +51,7 @@ static OPT_TAB_WIDTH: &str = "tab-width";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String { fn usage() -> String {
format!("{} [OPTION]... [FILE]...", executable!()) format!("{} [OPTION]... [FILE]...", execution_phrase!())
} }
pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>; pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>;

View file

@ -29,7 +29,7 @@ static ABOUT: &str = "Print group memberships for each USERNAME or, \
(which may differ if the groups database has changed)."; (which may differ if the groups database has changed).";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USERNAME]...", executable!()) format!("{0} [OPTION]... [USERNAME]...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [HOSTNAME]", executable!()) format!("{0} [OPTION]... [HOSTNAME]", execution_phrase!())
} }
fn execute(args: impl uucore::Args) -> UResult<()> { fn execute(args: impl uucore::Args) -> UResult<()> {

View file

@ -77,7 +77,7 @@ mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USER]...", executable!()) format!("{0} [OPTION]... [USER]...", execution_phrase!())
} }
fn get_description() -> String { fn get_description() -> String {

View file

@ -89,7 +89,7 @@ impl Display for InstallError {
IE::DirNeedsArg() => write!( IE::DirNeedsArg() => write!(
f, f,
"{} with -d requires at least one argument.", "{} with -d requires at least one argument.",
executable!() util_name!()
), ),
IE::CreateDirFailed(dir, e) => { IE::CreateDirFailed(dir, e) => {
Display::fmt(&uio_error!(e, "failed to create {}", dir.display()), f) 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"; static ARG_FILES: &str = "files";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", execution_phrase!())
} }
/// Main install utility function, called from main.rs. /// Main install utility function, called from main.rs.

View file

@ -41,7 +41,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.accept_any(); .accept_any();
let (args, obs_signal) = handle_obsolete(args); 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
let mode = if matches.is_present(options::TABLE) || matches.is_present(options::TABLE_OLD) { let mode = if matches.is_present(options::TABLE) || matches.is_present(options::TABLE_OLD) {

View file

@ -20,7 +20,7 @@ pub mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} FILE1 FILE2", executable!()) format!("{0} FILE1 FILE2", execution_phrase!())
} }
pub fn normalize_error_message(e: Error) -> String { pub fn normalize_error_message(e: Error) -> String {

View file

@ -70,7 +70,7 @@ impl Display for LnError {
f, f,
"extra operand '{}'\nTry `{} --help` for more information.", "extra operand '{}'\nTry `{} --help` for more information.",
s, s,
executable!() execution_phrase!()
), ),
Self::InvalidBackupMode(s) => write!(f, "{}", s), Self::InvalidBackupMode(s) => write!(f, "{}", s),
} }
@ -98,7 +98,7 @@ fn usage() -> String {
{0} [OPTION]... TARGET (2nd form) {0} [OPTION]... TARGET (2nd form)
{0} [OPTION]... TARGET... DIRECTORY (3rd form) {0} [OPTION]... TARGET... DIRECTORY (3rd form)
{0} [OPTION]... -t DIRECTORY TARGET... (4th 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 { match settings.overwrite {
OverwriteMode::NoClobber => {} OverwriteMode::NoClobber => {}
OverwriteMode::Interactive => { OverwriteMode::Interactive => {
print!("{}: overwrite '{}'? ", executable!(), dst.display()); print!("{}: overwrite '{}'? ", util_name!(), dst.display());
if !read_yes() { if !read_yes() {
return Ok(()); return Ok(());
} }

View file

@ -36,7 +36,7 @@ fn get_userlogin() -> Option<String> {
static SUMMARY: &str = "Print user's login name"; static SUMMARY: &str = "Print user's login name";
fn usage() -> String { fn usage() -> String {
String::from(executable!()) execution_phrase!().to_string()
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -47,7 +47,7 @@ use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR};
use uucore::{fs::display_permissions, version_cmp::version_cmp}; use uucore::{fs::display_permissions, version_cmp::version_cmp};
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", execution_phrase!())
} }
pub mod options { pub mod options {

View file

@ -23,7 +23,7 @@ mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USER]", executable!()) format!("{0} [OPTION]... [USER]", execution_phrase!())
} }
#[uucore_procs::gen_uumain] #[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()))?; create_dir(path).map_err_context(|| format!("cannot create directory '{}'", path.display()))?;
if verbose { if verbose {
println!("{}: created directory '{}'", executable!(), path.display()); println!("{}: created directory '{}'", util_name!(), path.display());
} }
chmod(path, mode) chmod(path, mode)

View file

@ -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; use uucore::InvalidEncodingHandling;
static NAME: &str = "mknod";
static ABOUT: &str = "Create the special file NAME of the given TYPE."; static ABOUT: &str = "Create the special file NAME of the given TYPE.";
static USAGE: &str = "mknod [OPTION]... NAME TYPE [MAJOR MINOR]"; static USAGE: &str = "mknod [OPTION]... NAME TYPE [MAJOR MINOR]";
static LONG_HELP: &str = "Mandatory arguments to long options are mandatory for short options too. 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 { 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 // shows the error from the mknod syscall
libc::perror(c_str.as_ptr()); libc::perror(c_str.as_ptr());
} }
@ -113,7 +113,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if ch == 'p' { if ch == 'p' {
if matches.is_present("major") || matches.is_present("minor") { if matches.is_present("major") || matches.is_present("minor") {
eprintln!("Fifos do not have major and minor device numbers."); eprintln!("Fifos do not have major and minor device numbers.");
eprintln!("Try `{} --help` for more information.", NAME); eprintln!("Try `{} --help` for more information.", execution_phrase!());
1 1
} else { } else {
_mknod(file_name, S_IFIFO | mode, 0) _mknod(file_name, S_IFIFO | mode, 0)
@ -122,7 +122,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
match (matches.value_of("major"), matches.value_of("minor")) { match (matches.value_of("major"), matches.value_of("minor")) {
(None, None) | (_, None) | (None, _) => { (None, None) | (_, None) | (None, _) => {
eprintln!("Special files require major and minor device numbers."); eprintln!("Special files require major and minor device numbers.");
eprintln!("Try `{} --help` for more information.", NAME); eprintln!("Try `{} --help` for more information.", execution_phrase!());
1 1
} }
(Some(major), Some(minor)) => { (Some(major), Some(minor)) => {

View file

@ -37,7 +37,7 @@ static OPT_T: &str = "t";
static ARG_TEMPLATE: &str = "template"; static ARG_TEMPLATE: &str = "template";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [TEMPLATE]", executable!()) format!("{0} [OPTION]... [TEMPLATE]", execution_phrase!())
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -63,7 +63,7 @@ fn usage() -> String {
"{0} [OPTION]... [-T] SOURCE DEST "{0} [OPTION]... [-T] SOURCE DEST
{0} [OPTION]... SOURCE... DIRECTORY {0} [OPTION]... SOURCE... DIRECTORY
{0} [OPTION]... -t DIRECTORY SOURCE...", {0} [OPTION]... -t DIRECTORY SOURCE...",
executable!() execution_phrase!()
) )
} }
@ -296,7 +296,7 @@ fn exec(files: &[PathBuf], b: Behavior) -> i32 {
"mv: extra operand '{}'\n\ "mv: extra operand '{}'\n\
Try `{} --help` for more information.", Try `{} --help` for more information.",
files[2].display(), files[2].display(),
executable!() execution_phrase!()
); );
return 1; return 1;
} }
@ -353,7 +353,7 @@ fn rename(from: &Path, to: &Path, b: &Behavior) -> io::Result<()> {
match b.overwrite { match b.overwrite {
OverwriteMode::NoClobber => return Ok(()), OverwriteMode::NoClobber => return Ok(()),
OverwriteMode::Interactive => { OverwriteMode::Interactive => {
println!("{}: overwrite '{}'? ", executable!(), to.display()); println!("{}: overwrite '{}'? ", util_name!(), to.display());
if !read_yes() { if !read_yes() {
return Ok(()); return Ok(());
} }

View file

@ -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 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 least -20 (most favorable to the process) to 19 (least favorable to the
process).", process).",
executable!() execution_phrase!()
) )
} }
@ -54,7 +54,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if !matches.is_present(options::COMMAND) { if !matches.is_present(options::COMMAND) {
show_error!( show_error!(
"A command must be given with an adjustment.\nTry `{} --help` for more information.", "A command must be given with an adjustment.\nTry `{} --help` for more information.",
executable!() execution_phrase!()
); );
return 125; return 125;
} }

View file

@ -157,7 +157,7 @@ fn find_stdout() -> File {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} COMMAND [ARG]...\n {0} FLAG", executable!()) format!("{0} COMMAND [ARG]...\n {0} FLAG", execution_phrase!())
} }
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]

View file

@ -28,7 +28,7 @@ static OPT_IGNORE: &str = "ignore";
static ABOUT: &str = "Print the number of cores available to the current process."; static ABOUT: &str = "Print the number of cores available to the current process.";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTIONS]...", executable!()) format!("{0} [OPTIONS]...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -51,7 +51,7 @@ Multiple fields/ranges can be separated with commas
"; ";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [NUMBER]...", executable!()) format!("{0} [OPTION]... [NUMBER]...", execution_phrase!())
} }
fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: NumfmtOptions) -> Result<()> { fn handle_args<'a>(args: impl Iterator<Item = &'a str>, options: NumfmtOptions) -> Result<()> {

View file

@ -57,12 +57,7 @@ impl<'b> MultifileReader<'b> {
// print an error at the time that the file is needed, // print an error at the time that the file is needed,
// then move on the the next file. // then move on the the next file.
// This matches the behavior of the original `od` // This matches the behavior of the original `od`
eprintln!( eprintln!("{}: '{}': {}", util_name!(), fname, e);
"{}: '{}': {}",
executable!().split("::").next().unwrap(), // remove module
fname,
e
);
self.any_err = true self.any_err = true
} }
} }
@ -95,11 +90,7 @@ impl<'b> io::Read for MultifileReader<'b> {
Ok(0) => break, Ok(0) => break,
Ok(n) => n, Ok(n) => n,
Err(e) => { Err(e) => {
eprintln!( eprintln!("{}: I/O: {}", util_name!(), e);
"{}: I/O: {}",
executable!().split("::").next().unwrap(), // remove module
e
);
self.any_err = true; self.any_err = true;
break; break;
} }

View file

@ -25,7 +25,6 @@ enum Mode {
Both, // a combination of `Basic` and `Extra` Both, // a combination of `Basic` and `Extra`
} }
static NAME: &str = "pathchk";
static ABOUT: &str = "Check whether file names are valid or portable"; static ABOUT: &str = "Check whether file names are valid or portable";
mod options { mod options {
@ -40,7 +39,7 @@ const POSIX_PATH_MAX: usize = 256;
const POSIX_NAME_MAX: usize = 14; const POSIX_NAME_MAX: usize = 14;
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... NAME...", executable!()) format!("{0} [OPTION]... NAME...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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() { let mut res = if paths.is_none() {
show_error!( show_error!(
"missing operand\nTry `{} --help` for more information", "missing operand\nTry `{} --help` for more information",
NAME execution_phrase!()
); );
false false
} else { } else {

View file

@ -41,7 +41,7 @@ mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USER]...", executable!()) format!("{0} [OPTION]... [USER]...", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {

View file

@ -20,7 +20,7 @@ static OPT_NULL: &str = "null";
static ARG_VARIABLES: &str = "variables"; static ARG_VARIABLES: &str = "variables";
fn usage() -> String { fn usage() -> String {
format!("{0} [VARIABLE]... [OPTION]...", executable!()) format!("{0} [VARIABLE]... [OPTION]...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -281,11 +281,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let location = &args[0];
if args.len() <= 1 { if args.len() <= 1 {
println!( println!(
"{0}: missing operand\nTry `{0} --help` for more information.", "{0}: missing operand\nTry `{1} --help` for more information.",
location util_name!(),
execution_phrase!()
); );
return 1; return 1;
} }
@ -294,7 +294,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if formatstr == "--help" { if formatstr == "--help" {
print!("{} {}", LONGHELP_LEAD, LONGHELP_BODY); print!("{} {}", LONGHELP_LEAD, LONGHELP_BODY);
} else if formatstr == "--version" { } else if formatstr == "--version" {
println!("{} {}", executable!(), crate_version!()); println!("{} {}", util_name!(), crate_version!());
} else { } else {
let printf_args = &args[2..]; let printf_args = &args[2..];
memo::Memo::run_all(formatstr, printf_args); memo::Memo::run_all(formatstr, printf_args);

View file

@ -35,7 +35,7 @@ pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", execution_phrase!())
} }
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]

View file

@ -16,7 +16,6 @@ use std::io::{stdout, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use uucore::fs::{canonicalize, CanonicalizeMode}; use uucore::fs::{canonicalize, CanonicalizeMode};
const NAME: &str = "readlink";
const ABOUT: &str = "Print value of a symbolic link or canonical file name."; const ABOUT: &str = "Print value of a symbolic link or canonical file name.";
const OPT_CANONICALIZE: &str = "canonicalize"; const OPT_CANONICALIZE: &str = "canonicalize";
const OPT_CANONICALIZE_MISSING: &str = "canonicalize-missing"; const OPT_CANONICALIZE_MISSING: &str = "canonicalize-missing";
@ -30,7 +29,7 @@ const OPT_ZERO: &str = "zero";
const ARG_FILES: &str = "files"; const ARG_FILES: &str = "files";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
@ -60,12 +59,15 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
crash!( crash!(
1, 1,
"missing operand\nTry `{} --help` for more information", "missing operand\nTry `{} --help` for more information",
NAME execution_phrase!()
); );
} }
if no_newline && files.len() > 1 && !silent { 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; no_newline = false;
} }
@ -76,7 +78,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
Ok(path) => show(&path, no_newline, use_zero), Ok(path) => show(&path, no_newline, use_zero),
Err(err) => { Err(err) => {
if verbose { if verbose {
eprintln!("{}: {}: errno {}", NAME, f, err.raw_os_error().unwrap()); eprintln!(
"{}: {}: errno {}",
util_name!(),
f,
err.raw_os_error().unwrap()
);
} }
return 1; return 1;
} }
@ -86,7 +93,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
Ok(path) => show(&path, no_newline, use_zero), Ok(path) => show(&path, no_newline, use_zero),
Err(err) => { Err(err) => {
if verbose { if verbose {
eprintln!("{}: {}: errno {:?}", NAME, f, err.raw_os_error().unwrap()); eprintln!(
"{}: {}: errno {:?}",
util_name!(),
f,
err.raw_os_error().unwrap()
);
} }
return 1; return 1;
} }

View file

@ -23,7 +23,7 @@ static OPT_ZERO: &str = "zero";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -26,7 +26,7 @@ mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{} [-d DIR] TO [FROM]", executable!()) format!("{} [-d DIR] TO [FROM]", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -53,7 +53,7 @@ static OPT_VERBOSE: &str = "verbose";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", execution_phrase!())
} }
fn get_long_usage() -> String { 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 // Still check by hand and not use clap
// Because "rm -f" is a thing // Because "rm -f" is a thing
show_error!("missing an argument"); show_error!("missing an argument");
show_error!("for help, try '{0} --help'", executable!()); show_error!("for help, try '{0} --help'", execution_phrase!());
return 1; return 1;
} else { } else {
let options = Options { let options = Options {

View file

@ -27,7 +27,7 @@ static ENOTDIR: i32 = 20;
static ENOTDIR: i32 = 267; static ENOTDIR: i32 = 267;
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... DIRECTORY...", executable!()) format!("{0} [OPTION]... DIRECTORY...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -27,7 +27,7 @@ fn usage() -> String {
"{0} [OPTION]... LAST "{0} [OPTION]... LAST
{0} [OPTION]... FIRST LAST {0} [OPTION]... FIRST LAST
{0} [OPTION]... FIRST INCREMENT LAST", {0} [OPTION]... FIRST INCREMENT LAST",
executable!() execution_phrase!()
) )
} }
#[derive(Clone)] #[derive(Clone)]
@ -72,13 +72,13 @@ impl FromStr for Number {
Ok(value) if value.is_nan() => Err(format!( Ok(value) if value.is_nan() => Err(format!(
"invalid 'not-a-number' argument: '{}'\nTry `{} --help` for more information.", "invalid 'not-a-number' argument: '{}'\nTry `{} --help` for more information.",
s, s,
executable!(), execution_phrase!(),
)), )),
Ok(value) => Ok(Number::F64(value)), Ok(value) => Ok(Number::F64(value)),
Err(_) => Err(format!( Err(_) => Err(format!(
"invalid floating point argument: '{}'\nTry `{} --help` for more information.", "invalid floating point argument: '{}'\nTry `{} --help` for more information.",
s, s,
executable!(), execution_phrase!(),
)), )),
}, },
} }
@ -123,7 +123,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
show_error!( show_error!(
"invalid Zero increment value: '{}'\nTry `{} --help` for more information.", "invalid Zero increment value: '{}'\nTry `{} --help` for more information.",
numbers[1], numbers[1],
executable!() execution_phrase!()
); );
return 1; return 1;
} }

View file

@ -214,7 +214,7 @@ for even very expensive hardware probing to recover the data.
"; ";
fn usage() -> String { fn usage() -> String {
format!("{} [OPTION]... FILE...", executable!()) format!("{} [OPTION]... FILE...", execution_phrase!())
} }
static AFTER_HELP: &str = static AFTER_HELP: &str =

View file

@ -29,7 +29,7 @@ mod options {
fn usage() -> String { fn usage() -> String {
format!( format!(
"{0} {1}[SUFFIX]... \n {0} OPTION", "{0} {1}[SUFFIX]... \n {0} OPTION",
executable!(), execution_phrase!(),
options::NUMBER options::NUMBER
) )
} }

View file

@ -52,7 +52,6 @@ use uucore::InvalidEncodingHandling;
use crate::tmp_dir::TmpDirWrapper; use crate::tmp_dir::TmpDirWrapper;
const NAME: &str = "sort";
const ABOUT: &str = "Display sorted concatenation of all FILE(s)."; 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]. 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. Write the sorted concatenation of all FILE(s) to standard output.
Mandatory arguments for long options are mandatory for short options too. Mandatory arguments for long options are mandatory for short options too.
With no FILE, or when FILE is -, read standard input.", With no FILE, or when FILE is -, read standard input.",
NAME execution_phrase!()
) )
} }

View file

@ -21,8 +21,6 @@ use std::path::Path;
use std::{char, fs::remove_file}; use std::{char, fs::remove_file};
use uucore::parse_size::parse_size; use uucore::parse_size::parse_size;
static NAME: &str = "split";
static OPT_BYTES: &str = "bytes"; static OPT_BYTES: &str = "bytes";
static OPT_LINE_BYTES: &str = "line-bytes"; static OPT_LINE_BYTES: &str = "line-bytes";
static OPT_LINES: &str = "lines"; static OPT_LINES: &str = "lines";
@ -37,7 +35,7 @@ static ARG_INPUT: &str = "input";
static ARG_PREFIX: &str = "prefix"; static ARG_PREFIX: &str = "prefix";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [INPUT [PREFIX]]", NAME) format!("{0} [OPTION]... [INPUT [PREFIX]]", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
format!( format!(

View file

@ -883,7 +883,7 @@ impl Stater {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {

View file

@ -48,7 +48,7 @@ mod options {
} }
fn usage() -> String { 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")); 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, 125,
"{}\nTry `{} --help` for more information.", "{}\nTry `{} --help` for more information.",
e.0, e.0,
executable!() execution_phrase!()
) )
}); });

View file

@ -160,7 +160,7 @@ mod platform {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -33,7 +33,7 @@ struct Options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -23,7 +23,7 @@ use uucore::InvalidEncodingHandling;
static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION."; static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION.";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION] DURATION COMMAND...", executable!()) format!("{0} [OPTION] DURATION COMMAND...", execution_phrase!())
} }
const ERR_EXIT_STATUS: i32 = 125; const ERR_EXIT_STATUS: i32 = 125;

View file

@ -48,7 +48,7 @@ fn local_tm_to_filetime(tm: time::Tm) -> FileTime {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USER]", executable!()) format!("{0} [OPTION]... [USER]", execution_phrase!())
} }
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]

View file

@ -229,7 +229,7 @@ fn translate_input<T: SymbolTranslator>(
} }
fn usage() -> String { fn usage() -> String {
format!("{} [OPTION]... SET1 [SET2]", executable!()) format!("{} [OPTION]... SET1 [SET2]", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -264,7 +264,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if sets.is_empty() { if sets.is_empty() {
show_error!( show_error!(
"missing operand\nTry `{} --help` for more information.", "missing operand\nTry `{} --help` for more information.",
executable!() execution_phrase!()
); );
return 1; return 1;
} }
@ -273,7 +273,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
show_error!( show_error!(
"missing operand after '{}'\nTry `{} --help` for more information.", "missing operand after '{}'\nTry `{} --help` for more information.",
sets[0], sets[0],
executable!() execution_phrase!()
); );
return 1; return 1;
} }

View file

@ -64,7 +64,7 @@ pub mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {

View file

@ -24,7 +24,7 @@ mod options {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]...", executable!()) format!("{0} [OPTION]...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -50,7 +50,7 @@ const HOST_OS: &str = "Fuchsia";
const HOST_OS: &str = "Redox"; const HOST_OS: &str = "Redox";
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
let uname = return_if_err!(1, PlatformInfo::new()); let uname = return_if_err!(1, PlatformInfo::new());

View file

@ -222,7 +222,7 @@ fn opt_parsed<T: FromStr>(opt_name: &str, matches: &ArgMatches) -> Option<T> {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [INPUT [OUTPUT]]...", executable!()) format!("{0} [OPTION]... [INPUT [OUTPUT]]...", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {

View file

@ -23,7 +23,7 @@ static ABOUT: &str = "Unlink the file at [FILE].";
static OPT_PATH: &str = "FILE"; static OPT_PATH: &str = "FILE";
fn usage() -> String { fn usage() -> String {
format!("{} [OPTION]... FILE", executable!()) format!("{} [OPTION]... FILE", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
@ -44,13 +44,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
crash!( crash!(
1, 1,
"missing operand\nTry `{0} --help` for more information.", "missing operand\nTry `{0} --help` for more information.",
executable!() execution_phrase!()
); );
} else if paths.len() > 1 { } else if paths.len() > 1 {
crash!( crash!(
1, 1,
"extra operand: '{1}'\nTry `{0} --help` for more information.", "extra operand: '{1}'\nTry `{0} --help` for more information.",
executable!(), execution_phrase!(),
paths[1] paths[1]
); );
} }

View file

@ -33,7 +33,7 @@ extern "C" {
} }
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]...", executable!()) format!("{0} [OPTION]...", execution_phrase!())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -19,7 +19,7 @@ static ABOUT: &str = "Print the user names of users currently logged in to the c
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn usage() -> String { fn usage() -> String {
format!("{0} [FILE]", executable!()) format!("{0} [FILE]", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {

View file

@ -99,7 +99,7 @@ fn usage() -> String {
format!( format!(
"{0} [OPTION]... [FILE]... "{0} [OPTION]... [FILE]...
With no FILE, or when FILE is -, read standard input.", With no FILE, or when FILE is -, read standard input.",
executable!() execution_phrase!()
) )
} }

View file

@ -45,7 +45,7 @@ static RUNLEVEL_HELP: &str = "print current runlevel";
static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)"; static RUNLEVEL_HELP: &str = "print current runlevel (This is meaningless on non Linux)";
fn usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", executable!()) format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", execution_phrase!())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {

View file

@ -125,7 +125,7 @@ macro_rules! show_usage_error(
($($args:tt)+) => ({ ($($args:tt)+) => ({
eprint!("{}: ", $crate::util_name!()); eprint!("{}: ", $crate::util_name!());
eprintln!($($args)+); eprintln!($($args)+);
eprintln!("Try `{:?} --help` for more information.", $crate::executable!()); eprintln!("Try `{} --help` for more information.", $crate::execution_phrase!());
}) })
); );

View file

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