mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
refactor/uucore ~ make util_name and execution_phrase functions
Since util_name and execution_phrase no longer rely on features that are only available to macros, they may as well be plain functions.
This commit is contained in:
@@ -27,7 +27,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.after_help(SUMMARY)
|
||||
|
||||
@@ -29,13 +29,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
static BASE_CMD_PARSE_ERROR: i32 = 1;
|
||||
|
||||
fn usage() -> String {
|
||||
format!("{0} [OPTION]... [FILE]", execution_phrase!())
|
||||
format!("{0} [OPTION]... [FILE]", uucore::execution_phrase())
|
||||
}
|
||||
|
||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
let format = Format::Base32;
|
||||
let usage = usage();
|
||||
let name = util_name!();
|
||||
let name = uucore::util_name();
|
||||
|
||||
let config_result: Result<base_common::Config, String> =
|
||||
base_common::parse_base_cmd_args(args, &name, VERSION, ABOUT, &usage);
|
||||
@@ -59,5 +59,5 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
base_common::base_app(&util_name!(), VERSION, ABOUT)
|
||||
base_common::base_app(&uucore::util_name(), VERSION, ABOUT)
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
static BASE_CMD_PARSE_ERROR: i32 = 1;
|
||||
|
||||
fn usage() -> String {
|
||||
format!("{0} [OPTION]... [FILE]", execution_phrase!())
|
||||
format!("{0} [OPTION]... [FILE]", uucore::execution_phrase())
|
||||
}
|
||||
|
||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
let format = Format::Base64;
|
||||
let usage = usage();
|
||||
let name = util_name!();
|
||||
let name = uucore::util_name();
|
||||
let config_result: Result<base_common::Config, String> =
|
||||
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));
|
||||
|
||||
@@ -21,7 +21,7 @@ fn usage() -> String {
|
||||
format!(
|
||||
"{0} NAME [SUFFIX]
|
||||
{0} OPTION... NAME...",
|
||||
execution_phrase!()
|
||||
uucore::execution_phrase()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
crash!(
|
||||
1,
|
||||
"{1}\nTry '{0} --help' for more information.",
|
||||
execution_phrase!(),
|
||||
uucore::execution_phrase(),
|
||||
"missing operand"
|
||||
);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
crash!(
|
||||
1,
|
||||
"extra operand '{1}'\nTry '{0} --help' for more information.",
|
||||
execution_phrase!(),
|
||||
uucore::execution_phrase(),
|
||||
matches.values_of(options::NAME).unwrap().nth(2).unwrap()
|
||||
);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(SUMMARY)
|
||||
.arg(
|
||||
|
||||
@@ -43,11 +43,11 @@ const ENCODINGS: &[(&str, Format)] = &[
|
||||
];
|
||||
|
||||
fn usage() -> String {
|
||||
format!("{0} [OPTION]... [FILE]", execution_phrase!())
|
||||
format!("{0} [OPTION]... [FILE]", uucore::execution_phrase())
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
let mut app = base_common::base_app(&util_name!(), crate_version!(), ABOUT);
|
||||
let mut app = base_common::base_app(&uucore::util_name(), crate_version!(), ABOUT);
|
||||
for encoding in ENCODINGS {
|
||||
app = app.arg(Arg::with_name(encoding.0).long(encoding.0));
|
||||
}
|
||||
@@ -75,7 +75,7 @@ fn parse_cmd_args(args: impl uucore::Args) -> (Config, Format) {
|
||||
}
|
||||
|
||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
let name = util_name!();
|
||||
let name = uucore::util_name();
|
||||
let (config, format) = parse_cmd_args(args);
|
||||
// Create a reference to stdin so we can return a locked stdin from
|
||||
// parse_base_cmd_args
|
||||
|
||||
@@ -234,7 +234,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.name(NAME)
|
||||
.version(crate_version!())
|
||||
.usage(SYNTAX)
|
||||
@@ -396,7 +396,7 @@ fn cat_files(files: Vec<String>, options: &OutputOptions) -> UResult<()> {
|
||||
Ok(())
|
||||
} else {
|
||||
// each next line is expected to display "cat: …"
|
||||
let line_joiner = format!("\n{}: ", util_name!());
|
||||
let line_joiner = format!("\n{}: ", uucore::util_name());
|
||||
|
||||
Err(uucore::error::USimpleError::new(
|
||||
error_messages.len() as i32,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#![allow(clippy::upper_case_acronyms)]
|
||||
|
||||
use uucore::{execution_phrase, show_error, show_usage_error, show_warning, util_name};
|
||||
use uucore::{show_error, show_usage_error, show_warning};
|
||||
|
||||
use clap::{App, Arg};
|
||||
use selinux::{OpaqueSecurityContext, SecurityContext};
|
||||
@@ -56,7 +56,7 @@ fn get_usage() -> String {
|
||||
"{0} [OPTION]... CONTEXT FILE... \n \
|
||||
{0} [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... \n \
|
||||
{0} [OPTION]... --reference=RFILE FILE...",
|
||||
execution_phrase!()
|
||||
uucore::execution_phrase()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(VERSION)
|
||||
.about(ABOUT)
|
||||
.arg(
|
||||
@@ -563,7 +563,7 @@ fn process_file(
|
||||
if options.verbose {
|
||||
println!(
|
||||
"{}: Changing security context of: {}",
|
||||
util_name!(),
|
||||
uucore::util_name(),
|
||||
file_full_name.to_string_lossy()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ const FTS_LOGICAL: u8 = 1 << 2;
|
||||
fn usage() -> String {
|
||||
format!(
|
||||
"{0} [OPTION]... GROUP FILE...\n {0} [OPTION]... --reference=RFILE FILE...",
|
||||
execution_phrase!()
|
||||
uucore::execution_phrase()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(VERSION)
|
||||
.about(ABOUT)
|
||||
.arg(
|
||||
|
||||
@@ -41,7 +41,7 @@ fn usage() -> String {
|
||||
"{0} [OPTION]... MODE[,MODE]... FILE...
|
||||
or: {0} [OPTION]... OCTAL-MODE FILE...
|
||||
or: {0} [OPTION]... --reference=RFILE FILE...",
|
||||
execution_phrase!()
|
||||
uucore::execution_phrase()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.arg(
|
||||
|
||||
@@ -64,7 +64,7 @@ const FTS_LOGICAL: u8 = 1 << 2;
|
||||
fn usage() -> String {
|
||||
format!(
|
||||
"{0} [OPTION]... [OWNER][:[GROUP]] FILE...\n{0} [OPTION]... --reference=RFILE FILE...",
|
||||
execution_phrase!()
|
||||
uucore::execution_phrase()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.arg(
|
||||
|
||||
@@ -16,7 +16,7 @@ use std::io::Error;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
|
||||
use uucore::{entries, execution_phrase, InvalidEncodingHandling};
|
||||
use uucore::{entries, InvalidEncodingHandling};
|
||||
|
||||
static ABOUT: &str = "Run COMMAND with root directory set to NEWROOT.";
|
||||
static SYNTAX: &str = "[OPTION]... NEWROOT [COMMAND [ARG]...]";
|
||||
@@ -46,7 +46,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
None => crash!(
|
||||
1,
|
||||
"Missing operand: NEWROOT\nTry '{} --help' for more information.",
|
||||
execution_phrase!()
|
||||
uucore::execution_phrase()
|
||||
),
|
||||
};
|
||||
|
||||
@@ -91,7 +91,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.usage(SYNTAX)
|
||||
|
||||
@@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.name(NAME)
|
||||
.version(crate_version!())
|
||||
.about(SUMMARY)
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
// spell-checker:ignore (ToDO) delim mkdelim
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fs::File;
|
||||
use std::io::{self, stdin, BufRead, BufReader, Stdin};
|
||||
@@ -32,7 +29,7 @@ mod options {
|
||||
}
|
||||
|
||||
fn usage() -> String {
|
||||
format!("{} [OPTION]... FILE1 FILE2", execution_phrase!())
|
||||
format!("{} [OPTION]... FILE1 FILE2", uucore::execution_phrase())
|
||||
}
|
||||
|
||||
fn mkdelim(col: usize, opts: &ArgMatches) -> String {
|
||||
@@ -148,7 +145,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.after_help(LONG_HELP)
|
||||
|
||||
+4
-4
@@ -99,7 +99,7 @@ quick_error! {
|
||||
NotImplemented(opt: String) { display("Option '{}' not yet implemented.", opt) }
|
||||
|
||||
/// Invalid arguments to backup
|
||||
Backup(description: String) { display("{}\nTry '{} --help' for more information.", description, execution_phrase!()) }
|
||||
Backup(description: String) { display("{}\nTry '{} --help' for more information.", description, uucore::execution_phrase()) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ fn usage() -> String {
|
||||
"{0} [OPTION]... [-T] SOURCE DEST
|
||||
{0} [OPTION]... SOURCE... DIRECTORY
|
||||
{0} [OPTION]... -t DIRECTORY SOURCE...",
|
||||
execution_phrase!()
|
||||
uucore::execution_phrase()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ static DEFAULT_ATTRIBUTES: &[Attribute] = &[
|
||||
];
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.arg(Arg::with_name(options::TARGET_DIRECTORY)
|
||||
@@ -1060,7 +1060,7 @@ impl OverwriteMode {
|
||||
match *self {
|
||||
OverwriteMode::NoClobber => Err(Error::NotAllFilesCopied),
|
||||
OverwriteMode::Interactive(_) => {
|
||||
if prompt_yes!("{}: overwrite {}? ", util_name!(), path.display()) {
|
||||
if prompt_yes!("{}: overwrite {}? ", uucore::util_name(), path.display()) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::Skipped(format!(
|
||||
|
||||
@@ -35,7 +35,10 @@ mod options {
|
||||
}
|
||||
|
||||
fn usage() -> String {
|
||||
format!("{0} [OPTION]... FILE PATTERN...", execution_phrase!())
|
||||
format!(
|
||||
"{0} [OPTION]... FILE PATTERN...",
|
||||
uucore::execution_phrase()
|
||||
)
|
||||
}
|
||||
|
||||
/// Command line options for csplit.
|
||||
@@ -739,7 +742,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(SUMMARY)
|
||||
.arg(
|
||||
|
||||
@@ -548,7 +548,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.name(NAME)
|
||||
.version(crate_version!())
|
||||
.usage(SYNTAX)
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
// spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use chrono::{DateTime, FixedOffset, Local, Offset, Utc};
|
||||
#[cfg(windows)]
|
||||
use chrono::{Datelike, Timelike};
|
||||
@@ -253,7 +250,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.arg(
|
||||
|
||||
+1
-3
@@ -7,8 +7,6 @@
|
||||
|
||||
// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
use uucore::InvalidEncodingHandling;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -1046,7 +1044,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> clap::App<'static, 'static> {
|
||||
clap::App::new(util_name!())
|
||||
clap::App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.arg(
|
||||
|
||||
+3
-3
@@ -80,7 +80,7 @@ struct Filesystem {
|
||||
}
|
||||
|
||||
fn usage() -> String {
|
||||
format!("{0} [OPTION]... [FILE]...", execution_phrase!())
|
||||
format!("{0} [OPTION]... [FILE]...", uucore::execution_phrase())
|
||||
}
|
||||
|
||||
impl FsSelector {
|
||||
@@ -295,7 +295,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if matches.is_present(OPT_INODES) {
|
||||
println!("{}: doesn't support -i option", util_name!());
|
||||
println!("{}: doesn't support -i option", uucore::util_name());
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@@ -427,7 +427,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.arg(
|
||||
|
||||
@@ -63,7 +63,7 @@ pub fn guess_syntax() -> OutputFmt {
|
||||
}
|
||||
|
||||
fn usage() -> String {
|
||||
format!("{0} {1}", execution_phrase!(), SYNTAX)
|
||||
format!("{0} {1}", uucore::execution_phrase(), SYNTAX)
|
||||
}
|
||||
|
||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
@@ -153,7 +153,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> App<'static, 'static> {
|
||||
App::new(util_name!())
|
||||
App::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(SUMMARY)
|
||||
.after_help(LONG_HELP)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user