1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #2471 from miDeb/real-exe-name

make executable!() return the real executable name
This commit is contained in:
Sylvestre Ledru 2021-08-22 16:55:06 +02:00 committed by GitHub
commit 114c9a409c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
114 changed files with 675 additions and 493 deletions

View file

@ -70,6 +70,7 @@ fn main() {
Some(OsString::from(*util)) Some(OsString::from(*util))
} else { } else {
// unmatched binary name => regard as multi-binary container and advance argument list // unmatched binary name => regard as multi-binary container and advance argument list
uucore::set_utility_is_second_arg();
args.next() args.next()
}; };

View file

@ -27,7 +27,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(SUMMARY) .after_help(SUMMARY)

View file

@ -28,17 +28,17 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
static BASE_CMD_PARSE_ERROR: i32 = 1; static BASE_CMD_PARSE_ERROR: i32 = 1;
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]", executable!()) format!("{0} [OPTION]... [FILE]", uucore::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 = get_usage(); let usage = usage();
let name = executable!(); let name = uucore::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));
// Create a reference to stdin so we can return a locked stdin from // 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.wrap_cols,
config.ignore_garbage, config.ignore_garbage,
config.decode, config.decode,
name, &name,
); );
0 0
} }
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(&uucore::util_name(), VERSION, ABOUT)
} }

View file

@ -29,16 +29,16 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
static BASE_CMD_PARSE_ERROR: i32 = 1; static BASE_CMD_PARSE_ERROR: i32 = 1;
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]", executable!()) format!("{0} [OPTION]... [FILE]", uucore::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 = get_usage(); let usage = usage();
let name = executable!(); let name = uucore::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));
// Create a reference to stdin so we can return a locked stdin from // 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.wrap_cols,
config.ignore_garbage, config.ignore_garbage,
config.decode, config.decode,
name, &name,
); );
0 0

View file

@ -17,11 +17,11 @@ use uucore::InvalidEncodingHandling;
static SUMMARY: &str = "Print NAME with any leading directory components removed static SUMMARY: &str = "Print NAME with any leading directory components removed
If specified, also remove a trailing SUFFIX"; If specified, also remove a trailing SUFFIX";
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{0} NAME [SUFFIX] "{0} NAME [SUFFIX]
{0} OPTION... NAME...", {0} OPTION... NAME...",
executable!() uucore::execution_phrase()
) )
} }
@ -36,7 +36,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
// //
// Argument parsing // Argument parsing
// //
@ -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!(), uucore::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!(), uucore::execution_phrase(),
matches.values_of(options::NAME).unwrap().nth(2).unwrap() 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> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.arg( .arg(

View file

@ -42,12 +42,12 @@ const ENCODINGS: &[(&str, Format)] = &[
("base2m", Format::Base2Msbf), ("base2m", Format::Base2Msbf),
]; ];
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]", executable!()) format!("{0} [OPTION]... [FILE]", uucore::execution_phrase())
} }
pub fn uu_app() -> App<'static, 'static> { 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(&uucore::util_name(), crate_version!(), ABOUT);
for encoding in ENCODINGS { for encoding in ENCODINGS {
app = app.arg(Arg::with_name(encoding.0).long(encoding.0)); 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) { 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( let matches = uu_app().usage(&usage[..]).get_matches_from(
args.collect_str(InvalidEncodingHandling::ConvertLossy) args.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(), .accept_any(),
@ -75,7 +75,7 @@ fn parse_cmd_args(args: impl uucore::Args) -> (Config, Format) {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let name = executable!(); let name = uucore::util_name();
let (config, format) = parse_cmd_args(args); let (config, format) = parse_cmd_args(args);
// Create a reference to stdin so we can return a locked stdin from // Create a reference to stdin so we can return a locked stdin from
// parse_base_cmd_args // parse_base_cmd_args
@ -88,7 +88,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
config.wrap_cols, config.wrap_cols,
config.ignore_garbage, config.ignore_garbage,
config.decode, config.decode,
name, &name,
); );
0 0

View file

@ -234,7 +234,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(SYNTAX) .usage(SYNTAX)
@ -396,7 +396,7 @@ fn cat_files(files: Vec<String>, options: &OutputOptions) -> UResult<()> {
Ok(()) Ok(())
} else { } else {
// each next line is expected to display "cat: …" // each next line is expected to display "cat: …"
let line_joiner = format!("\n{}: ", executable!()); let line_joiner = format!("\n{}: ", uucore::util_name());
Err(uucore::error::USimpleError::new( Err(uucore::error::USimpleError::new(
error_messages.len() as i32, error_messages.len() as i32,

View file

@ -2,7 +2,7 @@
#![allow(clippy::upper_case_acronyms)] #![allow(clippy::upper_case_acronyms)]
use uucore::{executable, show_error, show_usage_error, show_warning}; use uucore::{show_error, show_usage_error, show_warning};
use clap::{App, Arg}; use clap::{App, Arg};
use selinux::{OpaqueSecurityContext, SecurityContext}; use selinux::{OpaqueSecurityContext, SecurityContext};
@ -56,7 +56,7 @@ fn get_usage() -> String {
"{0} [OPTION]... CONTEXT FILE... \n \ "{0} [OPTION]... CONTEXT FILE... \n \
{0} [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... \n \ {0} [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... \n \
{0} [OPTION]... --reference=RFILE FILE...", {0} [OPTION]... --reference=RFILE FILE...",
executable!() uucore::execution_phrase()
) )
} }
@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(VERSION) .version(VERSION)
.about(ABOUT) .about(ABOUT)
.arg( .arg(
@ -563,7 +563,7 @@ fn process_file(
if options.verbose { if options.verbose {
println!( println!(
"{}: Changing security context of: {}", "{}: Changing security context of: {}",
executable!(), uucore::util_name(),
file_full_name.to_string_lossy() file_full_name.to_string_lossy()
); );
} }

View file

@ -59,10 +59,10 @@ const FTS_COMFOLLOW: u8 = 1;
const FTS_PHYSICAL: u8 = 1 << 1; const FTS_PHYSICAL: u8 = 1 << 1;
const FTS_LOGICAL: u8 = 1 << 2; const FTS_LOGICAL: u8 = 1 << 2;
fn get_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!() uucore::execution_phrase()
) )
} }
@ -71,7 +71,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let mut app = uu_app().usage(&usage[..]); let mut app = uu_app().usage(&usage[..]);
@ -197,7 +197,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(VERSION) .version(VERSION)
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -36,12 +36,12 @@ mod options {
pub const FILE: &str = "FILE"; pub const FILE: &str = "FILE";
} }
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{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!() uucore::execution_phrase()
) )
} }
@ -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"). // 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 mode_had_minus_prefix = strip_minus_from_mode(&mut args);
let usage = get_usage(); let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -116,7 +116,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -61,10 +61,10 @@ const FTS_COMFOLLOW: u8 = 1;
const FTS_PHYSICAL: u8 = 1 << 1; const FTS_PHYSICAL: u8 = 1 << 1;
const FTS_LOGICAL: u8 = 1 << 2; const FTS_LOGICAL: u8 = 1 << 2;
fn get_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!() uucore::execution_phrase()
) )
} }
@ -74,7 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -165,7 +165,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -18,7 +18,6 @@ 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, 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 uucore::execution_phrase()
), ),
}; };
@ -92,7 +91,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.usage(SYNTAX) .usage(SYNTAX)

View file

@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)

View file

@ -7,9 +7,6 @@
// spell-checker:ignore (ToDO) delim mkdelim // spell-checker:ignore (ToDO) delim mkdelim
#[macro_use]
extern crate uucore;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::fs::File; use std::fs::File;
use std::io::{self, stdin, BufRead, BufReader, Stdin}; use std::io::{self, stdin, BufRead, BufReader, Stdin};
@ -31,8 +28,8 @@ mod options {
pub const FILE_2: &str = "FILE2"; pub const FILE_2: &str = "FILE2";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{} [OPTION]... FILE1 FILE2", executable!()) format!("{} [OPTION]... FILE1 FILE2", uucore::execution_phrase())
} }
fn mkdelim(col: usize, opts: &ArgMatches) -> String { fn mkdelim(col: usize, opts: &ArgMatches) -> String {
@ -132,7 +129,7 @@ fn open_file(name: &str) -> io::Result<LineReader> {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
@ -148,7 +145,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)

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 'cp --help' for more information.", description) } Backup(description: String) { display("{}\nTry '{} --help' for more information.", description, uucore::execution_phrase()) }
} }
} }
@ -218,12 +218,12 @@ static LONG_HELP: &str = "";
static EXIT_OK: i32 = 0; static EXIT_OK: i32 = 0;
static EXIT_ERR: i32 = 1; static EXIT_ERR: i32 = 1;
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{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!() uucore::execution_phrase()
) )
} }
@ -293,7 +293,7 @@ static DEFAULT_ATTRIBUTES: &[Attribute] = &[
]; ];
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg(Arg::with_name(options::TARGET_DIRECTORY) .arg(Arg::with_name(options::TARGET_DIRECTORY)
@ -465,7 +465,7 @@ pub fn uu_app() -> App<'static, 'static> {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let matches = uu_app() let matches = uu_app()
.after_help(&*format!( .after_help(&*format!(
"{}\n{}", "{}\n{}",
@ -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 {}? ", uucore::util_name(), path.display()) {
Ok(()) Ok(())
} else { } else {
Err(Error::Skipped(format!( Err(Error::Skipped(format!(

View file

@ -34,8 +34,11 @@ mod options {
pub const PATTERN: &str = "pattern"; pub const PATTERN: &str = "pattern";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE PATTERN...", executable!()) format!(
"{0} [OPTION]... FILE PATTERN...",
uucore::execution_phrase()
)
} }
/// Command line options for csplit. /// Command line options for csplit.
@ -706,7 +709,7 @@ mod tests {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
@ -739,7 +742,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.arg( .arg(

View file

@ -548,7 +548,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(SYNTAX) .usage(SYNTAX)

View file

@ -8,9 +8,6 @@
// spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes // spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes
#[macro_use]
extern crate uucore;
use chrono::{DateTime, FixedOffset, Local, Offset, Utc}; use chrono::{DateTime, FixedOffset, Local, Offset, Utc};
#[cfg(windows)] #[cfg(windows)]
use chrono::{Datelike, Timelike}; use chrono::{Datelike, Timelike};
@ -253,7 +250,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -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 // 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; use uucore::InvalidEncodingHandling;
#[cfg(test)] #[cfg(test)]
@ -956,7 +954,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> clap::App<'static, 'static> { pub fn uu_app() -> clap::App<'static, 'static> {
clap::App::new(executable!()) clap::App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -79,8 +79,8 @@ struct Filesystem {
usage: FsUsage, usage: FsUsage,
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
} }
impl FsSelector { impl FsSelector {
@ -284,7 +284,7 @@ impl UError for DfError {
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
let paths: Vec<String> = matches let paths: Vec<String> = matches
@ -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", uucore::util_name());
return Ok(()); return Ok(());
} }
} }
@ -427,7 +427,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -62,8 +62,8 @@ pub fn guess_syntax() -> OutputFmt {
} }
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} {1}", executable!(), SYNTAX) format!("{0} {1}", uucore::execution_phrase(), SYNTAX)
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
@ -71,7 +71,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(&args); let matches = uu_app().usage(&usage[..]).get_matches_from(&args);
@ -153,7 +153,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.after_help(LONG_HELP) .after_help(LONG_HELP)

View file

@ -20,8 +20,8 @@ mod options {
pub const DIR: &str = "dir"; pub const DIR: &str = "dir";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION] NAME...", executable!()) format!("{0} [OPTION] NAME...", uucore::execution_phrase())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -37,7 +37,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -86,7 +86,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.about(ABOUT) .about(ABOUT)
.version(crate_version!()) .version(crate_version!())
.arg( .arg(

View file

@ -70,7 +70,6 @@ mod options {
pub const FILE: &str = "FILE"; pub const FILE: &str = "FILE";
} }
const NAME: &str = "du";
const SUMMARY: &str = "estimate file space usage"; const SUMMARY: &str = "estimate file space usage";
const LONG_HELP: &str = " const LONG_HELP: &str = "
Display values are in units of the first available SIZE from --block-size, Display values are in units of the first available SIZE from --block-size,
@ -87,7 +86,7 @@ const UNITS: [(char, u32); 6] = [('E', 6), ('P', 5), ('T', 4), ('G', 3), ('M', 2
struct Options { struct Options {
all: bool, all: bool,
program_name: String, util_name: String,
max_depth: Option<usize>, max_depth: Option<usize>,
total: bool, total: bool,
separate_dirs: bool, separate_dirs: bool,
@ -295,7 +294,7 @@ fn du(
safe_writeln!( safe_writeln!(
stderr(), stderr(),
"{}: cannot read directory '{}': {}", "{}: cannot read directory '{}': {}",
options.program_name, options.util_name,
my_stat.path.display(), my_stat.path.display(),
e e
); );
@ -393,11 +392,11 @@ fn convert_size_other(size: u64, _multiplier: u64, block_size: u64) -> String {
format!("{}", ((size as f64) / (block_size as f64)).ceil()) format!("{}", ((size as f64) / (block_size as f64)).ceil())
} }
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{0} [OPTION]... [FILE]... "{0} [OPTION]... [FILE]...
{0} [OPTION]... --files0-from=F", {0} [OPTION]... --files0-from=F",
executable!() uucore::execution_phrase()
) )
} }
@ -424,7 +423,8 @@ Valid arguments are:
- 'long-iso' - 'long-iso'
- 'iso' - 'iso'
Try '{} --help' for more information.", Try '{} --help' for more information.",
s, NAME s,
uucore::execution_phrase()
), ),
DuError::InvalidTimeArg(s) => write!( DuError::InvalidTimeArg(s) => write!(
f, f,
@ -456,7 +456,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -466,7 +466,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let options = Options { let options = Options {
all: matches.is_present(options::ALL), all: matches.is_present(options::ALL),
program_name: NAME.to_owned(), util_name: uucore::util_name(),
max_depth, max_depth,
total: matches.is_present(options::TOTAL), total: matches.is_present(options::TOTAL),
separate_dirs: matches.is_present(options::SEPARATE_DIRS), separate_dirs: matches.is_present(options::SEPARATE_DIRS),
@ -625,7 +625,7 @@ fn parse_depth(max_depth_str: Option<&str>, summarize: bool) -> UResult<Option<u
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.after_help(LONG_HELP) .after_help(LONG_HELP)

View file

@ -132,7 +132,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
// TrailingVarArg specifies the final positional argument is a VarArg // TrailingVarArg specifies the final positional argument is a VarArg
// and it doesn't attempts the parse any further args. // and it doesn't attempts the parse any further args.

View file

@ -32,8 +32,8 @@ static LONG_HELP: &str = "";
static DEFAULT_TABSTOP: usize = 8; static DEFAULT_TABSTOP: usize = 8;
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", uucore::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
@ -170,7 +170,7 @@ impl Options {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
expand(Options::new(&matches)); expand(Options::new(&matches));
@ -178,7 +178,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)

View file

@ -18,7 +18,7 @@ const VERSION: &str = "version";
const HELP: &str = "help"; const HELP: &str = "help";
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.arg(Arg::with_name(VERSION).long(VERSION)) .arg(Arg::with_name(VERSION).long(VERSION))
.arg(Arg::with_name(HELP).long(HELP)) .arg(Arg::with_name(HELP).long(HELP))
} }
@ -140,5 +140,5 @@ Environment variables:
} }
fn print_version() { fn print_version() {
println!("{} {}", executable!(), crate_version!()); println!("{} {}", uucore::util_name(), crate_version!());
} }

View file

@ -75,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
.arg(Arg::with_name(options::NUMBER).multiple(true)) .arg(Arg::with_name(options::NUMBER).multiple(true))

View file

@ -9,7 +9,7 @@
extern crate uucore; extern crate uucore;
use clap::App; use clap::App;
use uucore::{error::UResult, executable}; use uucore::error::UResult;
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@ -18,5 +18,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
} }

View file

@ -50,8 +50,8 @@ static OPT_TAB_WIDTH: &str = "tab-width";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn get_usage() -> String { fn usage() -> String {
format!("{} [OPTION]... [FILE]...", executable!()) format!("{} [OPTION]... [FILE]...", uucore::execution_phrase())
} }
pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>; pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>;
@ -75,7 +75,7 @@ pub struct FmtOptions {
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -211,7 +211,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(SYNTAX) .usage(SYNTAX)

View file

@ -28,12 +28,12 @@ static ABOUT: &str = "Print group memberships for each USERNAME or, \
if no USERNAME is specified, for\nthe current process \ if no USERNAME is specified, for\nthe current process \
(which may differ if the groups database has changed)."; (which may differ if the groups database has changed).";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USERNAME]...", executable!()) format!("{0} [OPTION]... [USERNAME]...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -85,7 +85,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -342,7 +342,7 @@ pub fn uu_app_common() -> App<'static, 'static> {
const TEXT_HELP: &str = "read in text mode"; const TEXT_HELP: &str = "read in text mode";
#[cfg(not(windows))] #[cfg(not(windows))]
const TEXT_HELP: &str = "read in text mode (default)"; const TEXT_HELP: &str = "read in text mode (default)";
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about("Compute and check message digests.") .about("Compute and check message digests.")
.arg( .arg(

View file

@ -9,7 +9,7 @@ use clap::{crate_version, App, Arg};
use std::convert::TryFrom; use std::convert::TryFrom;
use std::ffi::OsString; use std::ffi::OsString;
use std::io::{self, ErrorKind, Read, Seek, SeekFrom, Write}; 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};
const EXIT_FAILURE: i32 = 1; const EXIT_FAILURE: i32 = 1;
const EXIT_SUCCESS: i32 = 0; const EXIT_SUCCESS: i32 = 0;
@ -41,7 +41,7 @@ use lines::zlines;
use take::take_all_but; use take::take_all_but;
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.usage(USAGE) .usage(USAGE)

View file

@ -29,7 +29,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.usage(SYNTAX) .usage(SYNTAX)
} }

View file

@ -53,11 +53,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
result result
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [HOSTNAME]", executable!()) format!("{0} [OPTION]... [HOSTNAME]", uucore::execution_phrase())
} }
fn execute(args: impl uucore::Args) -> UResult<()> { fn execute(args: impl uucore::Args) -> UResult<()> {
let usage = get_usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().usage(&usage[..]).get_matches_from(args);
match matches.value_of(OPT_HOST) { match matches.value_of(OPT_HOST) {
@ -73,7 +74,7 @@ fn execute(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -76,8 +76,8 @@ mod options {
pub const ARG_USERS: &str = "USER"; pub const ARG_USERS: &str = "USER";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USER]...", executable!()) format!("{0} [OPTION]... [USER]...", uucore::execution_phrase())
} }
fn get_description() -> String { fn get_description() -> String {
@ -127,7 +127,7 @@ struct State {
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = get_usage(); let usage = usage();
let after_help = get_description(); let after_help = get_description();
let matches = uu_app() let matches = uu_app()
@ -347,7 +347,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -86,11 +86,13 @@ impl Display for InstallError {
use InstallError as IE; use InstallError as IE;
match self { match self {
IE::Unimplemented(opt) => write!(f, "Unimplemented feature: {}", opt), IE::Unimplemented(opt) => write!(f, "Unimplemented feature: {}", opt),
IE::DirNeedsArg() => write!( IE::DirNeedsArg() => {
f, write!(
"{} with -d requires at least one argument.", f,
executable!() "{} with -d requires at least one argument.",
), uucore::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)
} }
@ -172,8 +174,8 @@ static OPT_CONTEXT: &str = "context";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
} }
/// Main install utility function, called from main.rs. /// Main install utility function, called from main.rs.
@ -182,7 +184,7 @@ fn get_usage() -> String {
/// ///
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -202,7 +204,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

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...", uucore::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) {
@ -76,7 +76,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -19,8 +19,8 @@ pub mod options {
pub static FILES: &str = "FILES"; pub static FILES: &str = "FILES";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} FILE1 FILE2", executable!()) format!("{0} FILE1 FILE2", uucore::execution_phrase())
} }
pub fn normalize_error_message(e: Error) -> String { pub fn normalize_error_message(e: Error) -> String {
@ -31,7 +31,7 @@ pub fn normalize_error_message(e: Error) -> String {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
let files: Vec<_> = matches let files: Vec<_> = matches
@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

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!() uucore::execution_phrase()
), ),
Self::InvalidBackupMode(s) => write!(f, "{}", s), Self::InvalidBackupMode(s) => write!(f, "{}", s),
} }
@ -92,17 +92,17 @@ impl UError for LnError {
} }
} }
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{0} [OPTION]... [-T] TARGET LINK_NAME (1st form) "{0} [OPTION]... [-T] TARGET LINK_NAME (1st form)
{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!() uucore::execution_phrase()
) )
} }
fn get_long_usage() -> String { fn long_usage() -> String {
String::from( String::from(
" In the 1st form, create a link to TARGET with the name LINK_NAME. " 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. 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] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = get_usage(); let usage = usage();
let long_usage = get_long_usage(); let long_usage = long_usage();
let matches = uu_app() let matches = uu_app()
.usage(&usage[..]) .usage(&usage[..])
@ -196,7 +196,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(
@ -435,7 +435,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 '{}'? ", uucore::util_name(), dst.display());
if !read_yes() { if !read_yes() {
return Ok(()); return Ok(());
} }

View file

@ -35,8 +35,8 @@ fn get_userlogin() -> Option<String> {
static SUMMARY: &str = "Print user's login name"; static SUMMARY: &str = "Print user's login name";
fn get_usage() -> String { fn usage() -> String {
String::from(executable!()) uucore::execution_phrase()
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
@ -44,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let _ = uu_app().usage(&usage[..]).get_matches_from(args); let _ = uu_app().usage(&usage[..]).get_matches_from(args);
match get_userlogin() { match get_userlogin() {
@ -56,7 +56,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(SUMMARY) .about(SUMMARY)
} }

View file

@ -46,8 +46,8 @@ use unicode_width::UnicodeWidthStr;
use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; 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 get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
} }
pub mod options { pub mod options {
@ -603,7 +603,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let app = uu_app().usage(&usage[..]); let app = uu_app().usage(&usage[..]);
@ -618,7 +618,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about( .about(
"By default, ls will list the files and contents of any directories on \ "By default, ls will list the files and contents of any directories on \

View file

@ -22,13 +22,13 @@ mod options {
pub const DIRS: &str = "dirs"; pub const DIRS: &str = "dirs";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USER]", executable!()) format!("{0} [OPTION]... [USER]", uucore::execution_phrase())
} }
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = get_usage(); let usage = usage();
// Linux-specific options, not implemented // Linux-specific options, not implemented
// opts.optflag("Z", "context", "set SELinux security context" + // opts.optflag("Z", "context", "set SELinux security context" +
@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .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()))?; 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 '{}'",
uucore::util_name(),
path.display()
);
} }
chmod(path, mode) chmod(path, mode)

View file

@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(USAGE) .usage(USAGE)

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(uucore::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,10 @@ 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.",
uucore::execution_phrase()
);
1 1
} else { } else {
_mknod(file_name, S_IFIFO | mode, 0) _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")) { 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.",
uucore::execution_phrase()
);
1 1
} }
(Some(major), Some(minor)) => { (Some(major), Some(minor)) => {
@ -145,7 +151,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.usage(USAGE) .usage(USAGE)
.after_help(LONG_HELP) .after_help(LONG_HELP)

View file

@ -36,8 +36,8 @@ static OPT_T: &str = "t";
static ARG_TEMPLATE: &str = "template"; static ARG_TEMPLATE: &str = "template";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [TEMPLATE]", executable!()) format!("{0} [OPTION]... [TEMPLATE]", uucore::execution_phrase())
} }
#[derive(Debug)] #[derive(Debug)]
@ -74,7 +74,7 @@ impl Display for MkTempError {
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -134,7 +134,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -93,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.about("A file perusal filter for CRT viewing.") .about("A file perusal filter for CRT viewing.")
.version(crate_version!()) .version(crate_version!())
.arg( .arg(

View file

@ -58,17 +58,17 @@ static OPT_VERBOSE: &str = "verbose";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{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!() uucore::execution_phrase()
) )
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let matches = uu_app() let matches = uu_app()
.after_help(&*format!( .after_help(&*format!(
@ -133,7 +133,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(
@ -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!() uucore::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 '{}'? ", uucore::util_name(), to.display());
if !read_yes() { if !read_yes() {
return Ok(()); return Ok(());
} }

View file

@ -22,7 +22,7 @@ pub mod options {
pub static COMMAND: &str = "COMMAND"; pub static COMMAND: &str = "COMMAND";
} }
fn get_usage() -> String { fn usage() -> String {
format!( format!(
" "
{0} [OPTIONS] [COMMAND [ARGS]] {0} [OPTIONS] [COMMAND [ARGS]]
@ -31,12 +31,12 @@ 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!() uucore::execution_phrase()
) )
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -53,8 +53,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
Some(nstr) => { Some(nstr) => {
if !matches.is_present(options::COMMAND) { if !matches.is_present(options::COMMAND) {
show_error!( show_error!(
"A command must be given with an adjustment.\nTry \"{} --help\" for more information.", "A command must be given with an adjustment.\nTry '{} --help' for more information.",
executable!() uucore::execution_phrase()
); );
return 125; return 125;
} }
@ -101,7 +101,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.setting(AppSettings::TrailingVarArg) .setting(AppSettings::TrailingVarArg)
.version(crate_version!()) .version(crate_version!())
.arg( .arg(

View file

@ -143,7 +143,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(USAGE) .usage(USAGE)

View file

@ -40,7 +40,7 @@ mod options {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
@ -71,7 +71,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)
@ -156,8 +156,11 @@ fn find_stdout() -> File {
} }
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} COMMAND [ARG]...\n {0} FLAG", executable!()) format!(
"{0} COMMAND [ARG]...\n {0} FLAG",
uucore::execution_phrase()
)
} }
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]

View file

@ -27,12 +27,12 @@ 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 get_usage() -> String { fn usage() -> String {
format!("{0} [OPTIONS]...", executable!()) format!("{0} [OPTIONS]...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
let mut ignore = match matches.value_of(OPT_IGNORE) { let mut ignore = match matches.value_of(OPT_IGNORE) {
@ -70,7 +70,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -50,8 +50,8 @@ FIELDS supports cut(1) style field ranges:
Multiple fields/ranges can be separated with commas Multiple fields/ranges can be separated with commas
"; ";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [NUMBER]...", executable!()) format!("{0} [OPTION]... [NUMBER]...", uucore::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<()> {
@ -154,7 +154,7 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -175,7 +175,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)

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!("{}: '{}': {}", uucore::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: {}", uucore::util_name(), e);
"{}: I/O: {}",
executable!().split("::").next().unwrap(), // remove module
e
);
self.any_err = true; self.any_err = true;
break; break;
} }

View file

@ -252,7 +252,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> clap::App<'static, 'static> { pub fn uu_app() -> clap::App<'static, 'static> {
clap::App::new(executable!()) clap::App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.usage(USAGE) .usage(USAGE)

View file

@ -52,7 +52,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

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 {
@ -39,12 +38,12 @@ mod options {
const POSIX_PATH_MAX: usize = 256; const POSIX_PATH_MAX: usize = 256;
const POSIX_NAME_MAX: usize = 14; const POSIX_NAME_MAX: usize = 14;
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... NAME...", executable!()) format!("{0} [OPTION]... NAME...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
@ -69,7 +68,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
// take necessary actions // take necessary actions
let paths = matches.values_of(options::PATH); let paths = matches.values_of(options::PATH);
let mut res = if paths.is_none() { let mut res = if paths.is_none() {
show_error!("missing operand\nTry {} --help for more information", NAME); show_error!(
"missing operand\nTry '{} --help' for more information",
uucore::execution_phrase()
);
false false
} else { } else {
true true
@ -96,7 +98,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -40,8 +40,8 @@ mod options {
pub const USER: &str = "user"; pub const USER: &str = "user";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USER]...", executable!()) format!("{0} [OPTION]... [USER]...", uucore::execution_phrase())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -57,7 +57,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -130,7 +130,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -23,7 +23,6 @@ use std::fs::{metadata, File};
use std::io::{stdin, stdout, BufRead, BufReader, Lines, Read, Stdout, Write}; use std::io::{stdin, stdout, BufRead, BufReader, Lines, Read, Stdout, Write};
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::FileTypeExt; use std::os::unix::fs::FileTypeExt;
use uucore::executable;
type IOError = std::io::Error; type IOError = std::io::Error;
@ -170,7 +169,7 @@ quick_error! {
pub fn uu_app() -> clap::App<'static, 'static> { pub fn uu_app() -> clap::App<'static, 'static> {
// TODO: migrate to clap to get more shell completions // TODO: migrate to clap to get more shell completions
clap::App::new(executable!()) clap::App::new(uucore::util_name())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {

View file

@ -7,9 +7,6 @@
/* last synced with: printenv (GNU coreutils) 8.13 */ /* last synced with: printenv (GNU coreutils) 8.13 */
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use std::env; use std::env;
@ -19,12 +16,12 @@ static OPT_NULL: &str = "null";
static ARG_VARIABLES: &str = "variables"; static ARG_VARIABLES: &str = "variables";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [VARIABLE]... [OPTION]...", executable!()) format!("{0} [VARIABLE]... [OPTION]...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -55,7 +52,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -2,9 +2,6 @@
// spell-checker:ignore (change!) each's // spell-checker:ignore (change!) each's
// spell-checker:ignore (ToDO) LONGHELP FORMATSTRING templating parameterizing formatstr // spell-checker:ignore (ToDO) LONGHELP FORMATSTRING templating parameterizing formatstr
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use uucore::InvalidEncodingHandling; use uucore::InvalidEncodingHandling;
@ -281,11 +278,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 uucore::util_name(),
uucore::execution_phrase()
); );
return 1; return 1;
} }
@ -294,7 +291,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!("{} {}", uucore::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);
@ -303,7 +300,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.arg(Arg::with_name(VERSION).long(VERSION)) .arg(Arg::with_name(VERSION).long(VERSION))
.arg(Arg::with_name(HELP).long(HELP)) .arg(Arg::with_name(HELP).long(HELP))
} }

View file

@ -659,7 +659,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(BRIEF) .usage(BRIEF)

View file

@ -34,13 +34,13 @@ pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {
Ok(path_buf) Ok(path_buf)
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
} }
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -66,7 +66,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

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, MissingHandling, ResolveMode}; use uucore::fs::{canonicalize, MissingHandling, ResolveMode};
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";
@ -29,12 +28,12 @@ const OPT_ZERO: &str = "zero";
const ARG_FILES: &str = "files"; const ARG_FILES: &str = "files";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
let mut no_newline = matches.is_present(OPT_NO_NEWLINE); let mut no_newline = matches.is_present(OPT_NO_NEWLINE);
@ -66,13 +65,16 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if files.is_empty() { if files.is_empty() {
crash!( crash!(
1, 1,
"missing operand\nTry {} --help for more information", "missing operand\nTry '{} --help' for more information",
NAME uucore::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",
uucore::util_name()
);
no_newline = false; no_newline = false;
} }
@ -83,7 +85,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 {}",
uucore::util_name(),
f,
err.raw_os_error().unwrap()
);
} }
return 1; return 1;
} }
@ -93,7 +100,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 {:?}",
uucore::util_name(),
f,
err.raw_os_error().unwrap()
);
} }
return 1; return 1;
} }
@ -105,7 +117,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -24,12 +24,12 @@ static OPT_LOGICAL: &str = "logical";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -58,7 +58,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -7,9 +7,6 @@
// spell-checker:ignore (ToDO) subpath absto absfrom absbase // spell-checker:ignore (ToDO) subpath absto absfrom absbase
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use std::env; use std::env;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -25,15 +22,15 @@ mod options {
pub const FROM: &str = "FROM"; pub const FROM: &str = "FROM";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{} [-d DIR] TO [FROM]", executable!()) format!("{} [-d DIR] TO [FROM]", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -82,7 +79,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -52,8 +52,8 @@ static OPT_VERBOSE: &str = "verbose";
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -74,7 +74,7 @@ fn get_long_usage() -> String {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -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'", uucore::execution_phrase());
return 1; return 1;
} else { } else {
let options = Options { let options = Options {
@ -140,7 +140,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)

View file

@ -26,12 +26,12 @@ static ENOTDIR: i32 = 20;
#[cfg(windows)] #[cfg(windows)]
static ENOTDIR: i32 = 267; static ENOTDIR: i32 = 267;
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... DIRECTORY...", executable!()) format!("{0} [OPTION]... DIRECTORY...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -53,7 +53,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -22,12 +22,12 @@ static OPT_WIDTHS: &str = "widths";
static ARG_NUMBERS: &str = "numbers"; static ARG_NUMBERS: &str = "numbers";
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{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!() uucore::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!(), uucore::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!(), uucore::execution_phrase(),
)), )),
}, },
} }
@ -86,7 +86,7 @@ impl FromStr for Number {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
let numbers = matches.values_of(ARG_NUMBERS).unwrap().collect::<Vec<_>>(); let numbers = matches.values_of(ARG_NUMBERS).unwrap().collect::<Vec<_>>();
@ -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!() uucore::execution_phrase()
); );
return 1; return 1;
} }
@ -163,7 +163,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.setting(AppSettings::AllowLeadingHyphen) .setting(AppSettings::AllowLeadingHyphen)
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)

View file

@ -214,8 +214,8 @@ static ABOUT: &str = "Overwrite the specified FILE(s) repeatedly, in order to ma
for even very expensive hardware probing to recover the data. for even very expensive hardware probing to recover the data.
"; ";
fn get_usage() -> String { fn usage() -> String {
format!("{} [OPTION]... FILE...", executable!()) format!("{} [OPTION]... FILE...", uucore::execution_phrase())
} }
static AFTER_HELP: &str = static AFTER_HELP: &str =
@ -271,7 +271,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let app = uu_app().usage(&usage[..]); let app = uu_app().usage(&usage[..]);
@ -331,7 +331,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(AFTER_HELP) .after_help(AFTER_HELP)

View file

@ -115,7 +115,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.template(TEMPLATE) .template(TEMPLATE)

View file

@ -26,17 +26,17 @@ mod options {
pub const NUMBER: &str = "NUMBER"; pub const NUMBER: &str = "NUMBER";
} }
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{0} {1}[SUFFIX]... \n {0} OPTION", "{0} {1}[SUFFIX]... \n {0} OPTION",
executable!(), uucore::execution_phrase(),
options::NUMBER options::NUMBER
) )
} }
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -49,7 +49,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)

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].
@ -1055,13 +1054,13 @@ impl FieldSelector {
} }
} }
fn get_usage() -> String { fn usage() -> String {
format!( format!(
"{0} [OPTION]... [FILE]... "{0} [OPTION]... [FILE]...
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 uucore::execution_phrase()
) )
} }
@ -1081,7 +1080,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args let args = args
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let mut settings: GlobalSettings = Default::default(); let mut settings: GlobalSettings = Default::default();
let matches = match uu_app().usage(&usage[..]).get_matches_from_safe(args) { let matches = match uu_app().usage(&usage[..]).get_matches_from_safe(args) {
@ -1287,7 +1286,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

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";
@ -36,8 +34,11 @@ static OPT_VERBOSE: &str = "verbose";
static ARG_INPUT: &str = "input"; static ARG_INPUT: &str = "input";
static ARG_PREFIX: &str = "prefix"; static ARG_PREFIX: &str = "prefix";
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [INPUT [PREFIX]]", NAME) format!(
"{0} [OPTION]... [INPUT [PREFIX]]",
uucore::execution_phrase()
)
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
format!( format!(
@ -47,12 +48,12 @@ fn get_long_usage() -> String {
Output fixed-size pieces of INPUT to PREFIXaa, PREFIX ab, ...; default 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 size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is
-, read standard input.", -, read standard input.",
get_usage() usage()
) )
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -127,7 +128,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about("Create output files containing consecutive or interleaved sections of input") .about("Create output files containing consecutive or interleaved sections of input")
// strategy (mutually exclusive) // strategy (mutually exclusive)

View file

@ -882,8 +882,8 @@ impl Stater {
} }
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -945,7 +945,7 @@ for details about the options it supports.
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -963,7 +963,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -47,8 +47,8 @@ mod options {
pub const COMMAND: &str = "command"; pub const COMMAND: &str = "command";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} OPTION... COMMAND", executable!()) format!("{0} OPTION... COMMAND", uucore::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"));
@ -152,12 +152,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let args = args let args = args
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().usage(&usage[..]).get_matches_from(args);
let options = ProgramOptions::try_from(&matches) let options = ProgramOptions::try_from(&matches).unwrap_or_else(|e| {
.unwrap_or_else(|e| crash!(125, "{}\nTry 'stdbuf --help' for more information.", e.0)); crash!(
125,
"{}\nTry '{} --help' for more information.",
e.0,
uucore::execution_phrase()
)
});
let mut command_values = matches.values_of::<&str>(options::COMMAND).unwrap(); let mut command_values = matches.values_of::<&str>(options::COMMAND).unwrap();
let mut command = Command::new(command_values.next().unwrap()); let mut command = Command::new(command_values.next().unwrap());
@ -185,7 +191,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help(LONG_HELP) .after_help(LONG_HELP)

View file

@ -140,7 +140,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(USAGE) .usage(USAGE)

View file

@ -159,12 +159,12 @@ mod platform {
} }
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... FILE...", executable!()) format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -193,7 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(USAGE) .usage(USAGE)

View file

@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about("output the last part of files") .about("output the last part of files")
// TODO: add usage // TODO: add usage

View file

@ -32,12 +32,12 @@ struct Options {
files: Vec<String>, files: Vec<String>,
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -57,7 +57,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.after_help("If a FILE is -, it refers to a file named - .") .after_help("If a FILE is -, it refers to a file named - .")

View file

@ -14,7 +14,6 @@ use clap::{crate_version, App, AppSettings};
use parser::{parse, Symbol}; use parser::{parse, Symbol};
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use std::path::Path; use std::path::Path;
use uucore::executable;
const USAGE: &str = "test EXPRESSION const USAGE: &str = "test EXPRESSION
or: test or: test
@ -87,7 +86,7 @@ the version described here. Please refer to your shell's documentation
for details about the options it supports."; for details about the options it supports.";
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.setting(AppSettings::DisableHelpFlags) .setting(AppSettings::DisableHelpFlags)
.setting(AppSettings::DisableVersion) .setting(AppSettings::DisableVersion)
} }

View file

@ -22,8 +22,11 @@ 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 get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION] DURATION COMMAND...", executable!()) format!(
"{0} [OPTION] DURATION COMMAND...",
uucore::execution_phrase()
)
} }
const ERR_EXIT_STATUS: i32 = 125; const ERR_EXIT_STATUS: i32 = 125;
@ -100,7 +103,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let app = uu_app().usage(&usage[..]); let app = uu_app().usage(&usage[..]);

View file

@ -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) FileTime::from_unix_time(ts.sec as i64, ts.nsec as u32)
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [USER]", executable!()) format!("{0} [OPTION]... [USER]", uucore::execution_phrase())
} }
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -129,7 +129,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -228,8 +228,8 @@ fn translate_input<T: SymbolTranslator>(
} }
} }
fn get_usage() -> String { fn usage() -> String {
format!("{} [OPTION]... SET1 [SET2]", executable!()) format!("{} [OPTION]... SET1 [SET2]", uucore::execution_phrase())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -243,7 +243,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -263,17 +263,17 @@ 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!() uucore::execution_phrase()
); );
return 1; return 1;
} }
if !(delete_flag || squeeze_flag) && sets.len() < 2 { if !(delete_flag || squeeze_flag) && sets.len() < 2 {
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!() uucore::execution_phrase()
); );
return 1; return 1;
} }
@ -312,7 +312,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -10,7 +10,6 @@ extern crate uucore;
use clap::App; use clap::App;
use uucore::error::UResult; use uucore::error::UResult;
use uucore::executable;
#[uucore_procs::gen_uumain] #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { 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> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
} }

View file

@ -63,8 +63,8 @@ pub mod options {
pub static ARG_FILES: &str = "files"; pub static ARG_FILES: &str = "files";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [FILE]...", executable!()) format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -90,7 +90,7 @@ fn get_long_usage() -> String {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -133,7 +133,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -90,7 +90,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.usage(USAGE) .usage(USAGE)
.about(SUMMARY) .about(SUMMARY)

View file

@ -9,9 +9,6 @@
// spell-checker:ignore (ToDO) ttyname filedesc // spell-checker:ignore (ToDO) ttyname filedesc
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use std::ffi::CStr; use std::ffi::CStr;
use std::io::Write; use std::io::Write;
@ -23,12 +20,12 @@ mod options {
pub const SILENT: &str = "silent"; pub const SILENT: &str = "silent";
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]...", executable!()) format!("{0} [OPTION]...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let args = args let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
@ -78,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

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]...", uucore::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());
@ -119,7 +119,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg(Arg::with_name(options::ALL) .arg(Arg::with_name(options::ALL)

View file

@ -102,7 +102,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(USAGE) .usage(USAGE)

View file

@ -221,8 +221,11 @@ fn opt_parsed<T: FromStr>(opt_name: &str, matches: &ArgMatches) -> Option<T> {
}) })
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [INPUT [OUTPUT]]...", executable!()) format!(
"{0} [OPTION]... [INPUT [OUTPUT]]...",
uucore::execution_phrase()
)
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -235,7 +238,7 @@ fn get_long_usage() -> String {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let long_usage = get_long_usage(); let long_usage = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -281,7 +284,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -22,8 +22,8 @@ use uucore::InvalidEncodingHandling;
static ABOUT: &str = "Unlink the file at [FILE]."; static ABOUT: &str = "Unlink the file at [FILE].";
static OPT_PATH: &str = "FILE"; static OPT_PATH: &str = "FILE";
fn get_usage() -> String { fn usage() -> String {
format!("{} [OPTION]... FILE", executable!()) format!("{} [OPTION]... FILE", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
@ -31,7 +31,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -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!() uucore::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!(), uucore::execution_phrase(),
paths[1] paths[1]
); );
} }
@ -95,7 +95,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg(Arg::with_name(OPT_PATH).hidden(true).multiple(true)) .arg(Arg::with_name(OPT_PATH).hidden(true).multiple(true))

View file

@ -32,12 +32,12 @@ extern "C" {
fn GetTickCount() -> uucore::libc::uint32_t; fn GetTickCount() -> uucore::libc::uint32_t;
} }
fn get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]...", executable!()) format!("{0} [OPTION]...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
let (boot_time, user_count) = process_utmpx(); let (boot_time, user_count) = process_utmpx();
@ -64,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -8,9 +8,6 @@
// spell-checker:ignore (paths) wtmp // spell-checker:ignore (paths) wtmp
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use uucore::utmpx::{self, Utmpx}; use uucore::utmpx::{self, Utmpx};
@ -18,8 +15,8 @@ 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 get_usage() -> String { fn usage() -> String {
format!("{0} [FILE]", executable!()) format!("{0} [FILE]", uucore::execution_phrase())
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -31,7 +28,7 @@ If FILE is not specified, use {}. /var/log/wtmp as FILE is common.",
} }
pub fn uumain(args: impl uucore::Args) -> i32 { pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage(); let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -65,7 +62,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg(Arg::with_name(ARG_FILES).takes_value(true).max_values(1)) .arg(Arg::with_name(ARG_FILES).takes_value(true).max_values(1))

View file

@ -95,11 +95,11 @@ pub mod options {
static ARG_FILES: &str = "files"; static ARG_FILES: &str = "files";
fn get_usage() -> String { 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!() uucore::execution_phrase()
) )
} }
@ -132,7 +132,7 @@ impl Input {
} }
pub fn uumain(args: impl uucore::Args) -> i32 { 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 matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -164,7 +164,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -44,8 +44,11 @@ static RUNLEVEL_HELP: &str = "print current runlevel";
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
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 get_usage() -> String { fn usage() -> String {
format!("{0} [OPTION]... [ FILE | ARG1 ARG2 ]", executable!()) format!(
"{0} [OPTION]... [ FILE | ARG1 ARG2 ]",
uucore::execution_phrase()
)
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
@ -61,7 +64,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.collect_str(InvalidEncodingHandling::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
let usage = get_usage(); let usage = usage();
let after_help = get_long_usage(); let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
@ -160,7 +163,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {
App::new(executable!()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.arg( .arg(

View file

@ -77,6 +77,47 @@ pub use crate::features::wide;
//## core functions //## core functions
use std::ffi::OsString; 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)
}
/// 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::<Vec<_>>()
.join(" ")
} else {
executable()
}
}
pub enum InvalidEncodingHandling { pub enum InvalidEncodingHandling {
Ignore, Ignore,

View file

@ -1,3 +1,5 @@
use std::sync::atomic::AtomicBool;
// This file is part of the uutils coreutils package. // This file is part of the uutils coreutils package.
// //
// (c) Alex Lyon <arcterus@mail.com> // (c) Alex Lyon <arcterus@mail.com>
@ -5,31 +7,17 @@
// For the full copyright and license information, please view the LICENSE // For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code. // file that was distributed with this source code.
/// Deduce the name of the binary from the current source code filename. /// Whether we were called as a multicall binary ("coreutils <utility>")
/// pub static UTILITY_IS_SECOND_ARG: AtomicBool = AtomicBool::new(false);
/// e.g.: `src/uu/cp/src/cp.rs` -> `cp`
#[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
}
})
);
#[macro_export] #[macro_export]
macro_rules! show( macro_rules! show(
($err:expr) => ({ ($err:expr) => ({
let e = $err; let e = $err;
uucore::error::set_exit_code(e.code()); $crate::error::set_exit_code(e.code());
eprintln!("{}: {}", executable!(), e); eprintln!("{}: {}", $crate::util_name(), e);
if e.usage() {
eprintln!("Try '{} --help' for more information.", executable!());
}
}) })
); );
@ -46,7 +34,7 @@ macro_rules! show_if_err(
#[macro_export] #[macro_export]
macro_rules! show_error( macro_rules! show_error(
($($args:tt)+) => ({ ($($args:tt)+) => ({
eprint!("{}: ", executable!()); eprint!("{}: ", $crate::util_name());
eprintln!($($args)+); eprintln!($($args)+);
}) })
); );
@ -55,7 +43,7 @@ macro_rules! show_error(
#[macro_export] #[macro_export]
macro_rules! show_error_custom_description ( macro_rules! show_error_custom_description (
($err:expr,$($args:tt)+) => ({ ($err:expr,$($args:tt)+) => ({
eprint!("{}: {}: ", executable!(), $err); eprint!("{}: {}: ", $crate::util_name(), $err);
eprintln!($($args)+); eprintln!($($args)+);
}) })
); );
@ -63,7 +51,7 @@ macro_rules! show_error_custom_description (
#[macro_export] #[macro_export]
macro_rules! show_warning( macro_rules! show_warning(
($($args:tt)+) => ({ ($($args:tt)+) => ({
eprint!("{}: warning: ", executable!()); eprint!("{}: warning: ", $crate::util_name());
eprintln!($($args)+); eprintln!($($args)+);
}) })
); );
@ -72,9 +60,19 @@ macro_rules! show_warning(
#[macro_export] #[macro_export]
macro_rules! show_usage_error( macro_rules! show_usage_error(
($($args:tt)+) => ({ ($($args:tt)+) => ({
eprint!("{}: ", executable!()); eprint!("{}: ", $crate::util_name());
eprintln!($($args)+); eprintln!($($args)+);
eprintln!("Try '{} --help' for more information.", executable!()); eprintln!("Try '{} --help' for more information.", $crate::execution_phrase());
})
);
//====
/// Calls `exit()` with the provided exit code.
#[macro_export]
macro_rules! exit(
($exit_code:expr) => ({
::std::process::exit($exit_code)
}) })
); );
@ -82,16 +80,8 @@ macro_rules! show_usage_error(
#[macro_export] #[macro_export]
macro_rules! crash( macro_rules! crash(
($exit_code:expr, $($args:tt)+) => ({ ($exit_code:expr, $($args:tt)+) => ({
show_error!($($args)+); $crate::show_error!($($args)+);
::std::process::exit($exit_code) $crate::exit!($exit_code)
})
);
/// Calls `exit()` with the provided exit code.
#[macro_export]
macro_rules! exit(
($exit_code:expr) => ({
::std::process::exit($exit_code)
}) })
); );
@ -102,11 +92,13 @@ macro_rules! crash_if_err(
($exit_code:expr, $exp:expr) => ( ($exit_code:expr, $exp:expr) => (
match $exp { match $exp {
Ok(m) => m, Ok(m) => m,
Err(f) => crash!($exit_code, "{}", f), Err(f) => $crate::crash!($exit_code, "{}", f),
} }
) )
); );
//====
/// Unwraps the Result. Instead of panicking, it shows the error and then /// Unwraps the Result. Instead of panicking, it shows the error and then
/// returns from the function with the provided exit code. /// returns from the function with the provided exit code.
/// Assumes the current function returns an i32 value. /// Assumes the current function returns an i32 value.
@ -116,13 +108,15 @@ macro_rules! return_if_err(
match $exp { match $exp {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => {
show_error!("{}", f); $crate::show_error!("{}", f);
return $exit_code; return $exit_code;
} }
} }
) )
); );
//====
#[macro_export] #[macro_export]
macro_rules! safe_write( macro_rules! safe_write(
($fd:expr, $($args:tt)+) => ( ($fd:expr, $($args:tt)+) => (
@ -150,32 +144,32 @@ macro_rules! safe_unwrap(
($exp:expr) => ( ($exp:expr) => (
match $exp { match $exp {
Ok(m) => m, Ok(m) => m,
Err(f) => crash!(1, "{}", f.to_string()) Err(f) => $crate::crash!(1, "{}", f.to_string())
} }
) )
); );
//-- message templates //-- message templates
//-- message templates : general //-- message templates : (join utility sub-macros)
#[macro_export] #[macro_export]
macro_rules! snippet_list_join_oxford { macro_rules! snippet_list_join_oxford_comma {
($conjunction:expr, $valOne:expr, $valTwo:expr) => ( ($conjunction:expr, $valOne:expr, $valTwo:expr) => (
format!("{}, {} {}", $valOne, $conjunction, $valTwo) format!("{}, {} {}", $valOne, $conjunction, $valTwo)
); );
($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => ( ($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => (
format!("{}, {}", $valOne, snippet_list_join_inner!($conjunction, $valTwo $(, $remaining_values)*)) format!("{}, {}", $valOne, $crate::snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*))
); );
} }
#[macro_export] #[macro_export]
macro_rules! snippet_list_join_or { macro_rules! snippet_list_join {
($valOne:expr, $valTwo:expr) => ( ($conjunction:expr, $valOne:expr, $valTwo:expr) => (
format!("{} or {}", $valOne, $valTwo) format!("{} {} {}", $valOne, $conjunction, $valTwo)
); );
($valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => ( ($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => (
format!("{}, {}", $valOne, snippet_list_join_oxford!("or", $valTwo $(, $remaining_values)*)) format!("{}, {}", $valOne, $crate::snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*))
); );
} }
@ -193,10 +187,10 @@ macro_rules! msg_invalid_input {
#[macro_export] #[macro_export]
macro_rules! msg_invalid_opt_use { macro_rules! msg_invalid_opt_use {
($about:expr, $flag:expr) => { ($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) => { ($about:expr, $long_flag:expr, $short_flag:expr) => {
msg_invalid_input!(format!( $crate::msg_invalid_input!(format!(
"The '{}' ('{}') option {}", "The '{}' ('{}') option {}",
$long_flag, $short_flag, $about $long_flag, $short_flag, $about
)) ))
@ -206,10 +200,10 @@ macro_rules! msg_invalid_opt_use {
#[macro_export] #[macro_export]
macro_rules! msg_opt_only_usable_if { macro_rules! msg_opt_only_usable_if {
($clause:expr, $flag:expr) => { ($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) => { ($clause:expr, $long_flag:expr, $short_flag:expr) => {
msg_invalid_opt_use!( $crate::msg_invalid_opt_use!(
format!("only usable if {}", $clause), format!("only usable if {}", $clause),
$long_flag, $long_flag,
$short_flag $short_flag
@ -220,13 +214,13 @@ macro_rules! msg_opt_only_usable_if {
#[macro_export] #[macro_export]
macro_rules! msg_opt_invalid_should_be { macro_rules! msg_opt_invalid_should_be {
($expects:expr, $received:expr, $flag:expr) => { ($expects:expr, $received:expr, $flag:expr) => {
msg_invalid_opt_use!( $crate::msg_invalid_opt_use!(
format!("expects {}, but was provided {}", $expects, $received), format!("expects {}, but was provided {}", $expects, $received),
$flag $flag
) )
}; };
($expects:expr, $received:expr, $long_flag:expr, $short_flag:expr) => { ($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), format!("expects {}, but was provided {}", $expects, $received),
$long_flag, $long_flag,
$short_flag $short_flag
@ -239,13 +233,13 @@ macro_rules! msg_opt_invalid_should_be {
#[macro_export] #[macro_export]
macro_rules! msg_expects_one_of { macro_rules! msg_expects_one_of {
($valOne:expr $(, $remaining_values:expr)*) => ( ($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_export]
macro_rules! msg_expects_no_more_than_one_of { macro_rules! msg_expects_no_more_than_one_of {
($valOne:expr $(, $remaining_values:expr)*) => ( ($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)*))) ;
); );
} }

View file

@ -120,7 +120,7 @@ impl<'a> CoreOptions<'a> {
macro_rules! app { macro_rules! app {
($syntax: expr, $summary: expr, $long_help: expr) => { ($syntax: expr, $summary: expr, $long_help: expr) => {
uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText { uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText {
name: executable!(), name: uucore::util_name(),
version: env!("CARGO_PKG_VERSION"), version: env!("CARGO_PKG_VERSION"),
syntax: $syntax, syntax: $syntax,
summary: $summary, summary: $summary,
@ -130,7 +130,7 @@ macro_rules! app {
}; };
($syntax: expr, $summary: expr, $long_help: expr, $display_usage: expr) => { ($syntax: expr, $summary: expr, $long_help: expr, $display_usage: expr) => {
uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText { uucore::coreopts::CoreOptions::new(uucore::coreopts::HelpText {
name: executable!(), name: uucore::util_name(),
version: env!("CARGO_PKG_VERSION"), version: env!("CARGO_PKG_VERSION"),
syntax: $syntax, syntax: $syntax,
summary: $summary, summary: $summary,

Some files were not shown because too many files have changed in this diff Show more