Merge pull request #8542 from sylvestre/clap-loca-improv-2

clap/locale: fix the colors for all programs (Closes: #8501)
This commit is contained in:
Daniel Hofstetter 2025-09-05 10:06:17 +02:00 committed by GitHub
commit 303a211044
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
121 changed files with 2452 additions and 1827 deletions

3
.vscode/cSpell.json vendored
View file

@ -29,7 +29,8 @@
"**/*.svg",
"src/uu/*/locales/*.ftl",
"src/uucore/locales/*.ftl",
".devcontainer/**"
".devcontainer/**",
"util/gnu-patches/**",
],
"enableGlobDot": true,

View file

@ -349,3 +349,12 @@ getcwd
# * other
weblate
algs
# translation tests
CLICOLOR
erreur
Utilisation
merror
merreur
verbo
inattendu

View file

@ -301,7 +301,7 @@ chrono = { version = "0.4.41", default-features = false, features = [
"alloc",
"clock",
] }
clap = { version = "4.5", features = ["wrap_help", "cargo"] }
clap = { version = "4.5", features = ["wrap_help", "cargo", "color"] }
clap_complete = "4.4"
clap_mangen = "0.2"
compare = "0.1.0"

View file

@ -6,13 +6,12 @@
use platform_info::*;
use clap::Command;
use uucore::LocalizedCommand;
use uucore::error::{UResult, USimpleError};
use uucore::translate;
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uu_app().get_matches_from_localized(args);
uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let uts =
PlatformInfo::new().map_err(|_e| USimpleError::new(1, translate!("cannot-get-system")))?;

View file

@ -10,7 +10,6 @@ use std::ffi::OsString;
use std::fs::File;
use std::io::{self, ErrorKind, Read, Seek, SeekFrom};
use std::path::{Path, PathBuf};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::encoding::{
BASE2LSBF, BASE2MSBF, EncodingWrapper, Format, SupportsFastDecodeAndEncode, Z85Wrapper,
@ -101,17 +100,17 @@ pub fn parse_base_cmd_args(
usage: &str,
) -> UResult<Config> {
let command = base_app(about, usage);
let matches = command.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(command, args)?;
Config::from(&matches)
}
pub fn base_app(about: &'static str, usage: &str) -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(about)
.override_usage(format_usage(usage))
.infer_long_args(true)
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd)
// Format arguments.
.arg(
Arg::new(options::DECODE)

View file

@ -15,7 +15,6 @@ use uucore::error::{UResult, UUsageError};
use uucore::format_usage;
use uucore::line_ending::LineEnding;
use uucore::LocalizedCommand;
use uucore::translate;
pub mod options {
@ -30,7 +29,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
//
// Argument parsing
//
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));

View file

@ -7,7 +7,6 @@
use clap::{Arg, ArgAction, Command};
use uu_base32::base_common::{self, BASE_CMD_PARSE_ERROR, Config};
use uucore::error::UClapError;
use uucore::translate;
use uucore::{
encoding::Format,
@ -64,9 +63,7 @@ pub fn uu_app() -> Command {
}
fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> {
let matches = uu_app()
.try_get_matches_from(args.collect_lossy())
.with_exit_code(1)?;
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args.collect_lossy())?;
let encodings = get_encodings();
let format = encodings

View file

@ -23,7 +23,6 @@ use std::os::unix::fs::FileTypeExt;
#[cfg(unix)]
use std::os::unix::net::UnixStream;
use thiserror::Error;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::UResult;
#[cfg(not(target_os = "windows"))]
@ -232,7 +231,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
}
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let number_mode = if matches.get_flag(options::NUMBER_NONBLANK) {
NumberingMode::NonEmpty

View file

@ -7,12 +7,11 @@
#![allow(clippy::upper_case_acronyms)]
use clap::builder::ValueParser;
use uucore::LocalizedCommand;
use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::translate;
use uucore::{display::Quotable, format_usage, show_error, show_warning};
use clap::{Arg, ArgAction, Command};
use clap::{Arg, ArgAction, ArgMatches, Command};
use selinux::{OpaqueSecurityContext, SecurityContext};
use std::borrow::Cow;
@ -58,9 +57,9 @@ pub mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let config = uu_app();
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let options = match parse_command_line(config, args) {
let options = match parse_command_line(&matches) {
Ok(r) => r,
Err(r) => {
if let Error::CommandLine(r) = r {
@ -155,20 +154,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("chcon-about"))
.override_usage(format_usage(&translate!("chcon-usage")))
.infer_long_args(true)
.disable_help_flag(true)
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd)
.args_override_self(true)
.arg(
Arg::new(options::HELP)
.long(options::HELP)
.help(translate!("chcon-help-help"))
.action(ArgAction::Help),
)
.disable_help_flag(true)
.arg(
Arg::new(options::dereference::DEREFERENCE)
.long(options::dereference::DEREFERENCE)
@ -183,6 +176,12 @@ pub fn uu_app() -> Command {
.help(translate!("chcon-help-no-dereference"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("help")
.long("help")
.help(translate!("help"))
.action(ArgAction::Help),
)
.arg(
Arg::new(options::preserve_root::PRESERVE_ROOT)
.long(options::preserve_root::PRESERVE_ROOT)
@ -304,9 +303,7 @@ struct Options {
files: Vec<PathBuf>,
}
fn parse_command_line(config: Command, args: impl uucore::Args) -> Result<Options> {
let matches = config.get_matches_from_localized(args);
fn parse_command_line(matches: &ArgMatches) -> Result<Options> {
let verbose = matches.get_flag(options::VERBOSE);
let (recursive_mode, affect_symlink_referent) = if matches.get_flag(options::RECURSIVE) {

View file

@ -98,12 +98,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("chgrp-about"))
.override_usage(format_usage(&translate!("chgrp-usage")))
.infer_long_args(true)
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd)
.disable_help_flag(true)
.arg(
Arg::new(options::HELP)

View file

@ -11,7 +11,6 @@ use std::fs;
use std::os::unix::fs::{MetadataExt, PermissionsExt};
use std::path::Path;
use thiserror::Error;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{ExitCode, UError, UResult, USimpleError, UUsageError, set_exit_code};
use uucore::fs::display_permissions_unix;
@ -111,9 +110,7 @@ fn extract_negative_modes(mut args: impl uucore::Args) -> (Option<String>, Vec<O
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let (parsed_cmode, args) = extract_negative_modes(args.skip(1)); // skip binary name
let matches = uu_app()
.after_help(translate!("chmod-after-help"))
.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let changes = matches.get_flag(options::CHANGES);
let quiet = matches.get_flag(options::QUIET);
@ -177,13 +174,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("chmod-about"))
.override_usage(format_usage(&translate!("chmod-usage")))
.help_template(uucore::localized_help_template(uucore::util_name()))
.args_override_self(true)
.infer_long_args(true)
.no_binary_name(true)
.disable_help_flag(true)
.after_help(translate!("chmod-after-help"))
.arg(
Arg::new(options::HELP)
.long(options::HELP)

View file

@ -14,7 +14,7 @@ use std::os::unix::prelude::OsStrExt;
use std::path::{Path, PathBuf};
use std::process;
use uucore::entries::{Locate, Passwd, grp2gid, usr2uid};
use uucore::error::{UClapError, UResult, UUsageError, set_exit_code};
use uucore::error::{UResult, UUsageError, set_exit_code};
use uucore::fs::{MissingHandling, ResolveMode, canonicalize};
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
use uucore::{format_usage, show};
@ -155,7 +155,8 @@ impl Options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
let matches =
uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 125)?;
let default_shell: &'static str = "/bin/sh";
let default_option: &'static str = "-i";
@ -234,13 +235,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("chroot-about"))
.override_usage(format_usage(&translate!("chroot-usage")))
.infer_long_args(true)
.trailing_var_arg(true)
.trailing_var_arg(true);
uucore::clap_localization::configure_localized_command(cmd)
.arg(
Arg::new(options::NEWROOT)
.value_hint(clap::ValueHint::DirPath)

View file

@ -20,7 +20,6 @@ use uucore::checksum::{
};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::{
encoding,
error::{FromIo, UResult, USimpleError},
@ -235,7 +234,7 @@ fn handle_tag_text_binary_flags<S: AsRef<OsStr>>(
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let check = matches.get_flag(options::CHECK);

View file

@ -10,7 +10,6 @@ use std::ffi::OsString;
use std::fs::{File, metadata};
use std::io::{self, BufRead, BufReader, Read, Stdin, stdin};
use std::path::Path;
use uucore::LocalizedCommand;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage;
use uucore::fs::paths_refer_to_same_file;
@ -283,7 +282,7 @@ fn open_file(name: &OsString, line_ending: LineEnding) -> io::Result<LineReader>
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED));
let filename1 = matches.get_one::<OsString>(options::FILE_1).unwrap();
let filename2 = matches.get_one::<OsString>(options::FILE_2).unwrap();

View file

@ -15,7 +15,6 @@ use std::os::unix::fs::{FileTypeExt, PermissionsExt};
use std::os::unix::net::UnixListener;
use std::path::{Path, PathBuf, StripPrefixError};
use std::{fmt, io};
use uucore::LocalizedCommand;
#[cfg(all(unix, not(target_os = "android")))]
use uucore::fsxattr::copy_xattrs;
use uucore::translate;
@ -782,7 +781,7 @@ pub fn uu_app() -> Command {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let options = Options::from_matches(&matches)?;

View file

@ -26,7 +26,6 @@ mod split_name;
use crate::csplit_error::CsplitError;
use crate::split_name::SplitName;
use uucore::LocalizedCommand;
use uucore::translate;
mod options {
@ -606,7 +605,7 @@ where
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
// get the file to split
let file_name = matches.get_one::<OsString>(options::FILE).unwrap();

View file

@ -18,7 +18,6 @@ use uucore::os_str_as_bytes;
use self::searcher::Searcher;
use matcher::{ExactMatcher, Matcher, WhitespaceMatcher};
use uucore::LocalizedCommand;
use uucore::ranges::Range;
use uucore::translate;
use uucore::{format_usage, show_error, show_if_err};
@ -483,7 +482,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
})
.collect();
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let complement = matches.get_flag(options::COMPLEMENT);
let only_delimited = matches.get_flag(options::ONLY_DELIMITED);

View file

@ -21,7 +21,6 @@ use uucore::{format_usage, show};
#[cfg(windows)]
use windows_sys::Win32::{Foundation::SYSTEMTIME, System::SystemInformation::SetSystemTime};
use uucore::LocalizedCommand;
use uucore::parser::shortcut_value_parser::ShortcutValueParser;
// Options
@ -114,7 +113,7 @@ impl From<&str> for Rfc3339Format {
#[uucore::main]
#[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let format = if let Some(form) = matches.get_one::<String>(OPT_FORMAT) {
if !form.starts_with('+') {

View file

@ -55,7 +55,6 @@ use nix::{
errno::Errno,
fcntl::{PosixFadviseAdvice, posix_fadvise},
};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult};
#[cfg(unix)]
@ -1416,7 +1415,7 @@ fn is_fifo(filename: &str) -> bool {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let settings: Settings = Parser::new().parse(
matches

View file

@ -11,7 +11,6 @@ mod table;
use blocks::HumanReadable;
use clap::builder::ValueParser;
use table::HeaderMode;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{UError, UResult, USimpleError, get_exit_code};
use uucore::fsext::{MountInfo, read_fs_list};
@ -407,7 +406,7 @@ impl UError for DfError {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
#[cfg(windows)]
{

View file

@ -14,7 +14,7 @@ use uucore::quoting_style::QuotingStyle;
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let command = uu_app();
let matches = command.get_matches_from(args);
let matches = uucore::clap_localization::handle_clap_result_with_exit_code(command, args, 2)?;
let mut default_quoting_style = false;
let mut default_format_style = false;

View file

@ -19,7 +19,6 @@ use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::{format_usage, parser::parse_glob};
mod options {
@ -122,7 +121,7 @@ fn generate_ls_colors(fmt: &OutputFmt, sep: &str) -> String {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let files = matches
.get_many::<OsString>(options::FILE)

View file

@ -6,7 +6,6 @@
use clap::{Arg, ArgAction, Command};
use std::ffi::OsString;
use std::path::Path;
use uucore::LocalizedCommand;
use uucore::display::print_verbatim;
use uucore::error::{UResult, UUsageError};
use uucore::format_usage;
@ -21,9 +20,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
.after_help(translate!("dirname-after-help"))
.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));
@ -69,6 +66,7 @@ pub fn uu_app() -> Command {
.override_usage(format_usage(&translate!("dirname-usage")))
.args_override_self(true)
.infer_long_args(true)
.after_help(translate!("dirname-after-help"))
.arg(
Arg::new(options::ZERO)
.long(options::ZERO)

View file

@ -27,7 +27,6 @@ use uucore::fsext::{MetadataTimeField, metadata_get_time};
use uucore::line_ending::LineEnding;
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::parser::parse_glob;
use uucore::parser::parse_size::{ParseSizeError, parse_size_u64};
use uucore::parser::shortcut_value_parser::ShortcutValueParser;
@ -583,7 +582,7 @@ fn read_files_from(file_name: &OsStr) -> Result<Vec<PathBuf>, std::io::Error> {
#[uucore::main]
#[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let summarize = matches.get_flag(options::SUMMARIZE);

29
src/uu/env/src/env.rs vendored
View file

@ -492,24 +492,27 @@ impl EnvAppData {
let original_args: Vec<OsString> = original_args.collect();
let args = self.process_all_string_arguments(&original_args)?;
let app = uu_app();
let matches = app
.try_get_matches_from(args)
.map_err(|e| -> Box<dyn UError> {
let matches = match app.try_get_matches_from(args) {
Ok(matches) => matches,
Err(e) => {
match e.kind() {
clap::error::ErrorKind::DisplayHelp
| clap::error::ErrorKind::DisplayVersion => e.into(),
| clap::error::ErrorKind::DisplayVersion => return Err(e.into()),
_ => {
// extent any real issue with parameter parsing by the ERROR_MSG_S_SHEBANG
let s = format!("{e}");
if !s.is_empty() {
let s = s.trim_end();
uucore::show_error!("{s}");
}
uucore::show_error!("{}", translate!("env-error-use-s-shebang"));
ExitCode::new(125)
// Use ErrorFormatter directly to handle error with shebang message callback
let formatter =
uucore::clap_localization::ErrorFormatter::new(uucore::util_name());
formatter.print_error_and_exit_with_callback(&e, 125, || {
eprintln!(
"{}: {}",
uucore::util_name(),
translate!("env-error-use-s-shebang")
);
});
}
}
})?;
}
};
Ok((original_args, matches))
}

View file

@ -243,49 +243,51 @@ fn expand_shortcuts(args: Vec<OsString>) -> Vec<OsString> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(expand_shortcuts(args.collect()))?;
let matches =
uucore::clap_localization::handle_clap_result(uu_app(), expand_shortcuts(args.collect()))?;
expand(&Options::new(&matches)?)
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("expand-about"))
.after_help(LONG_HELP)
.override_usage(format_usage(&translate!("expand-usage")))
.infer_long_args(true)
.args_override_self(true)
.arg(
Arg::new(options::INITIAL)
.long(options::INITIAL)
.short('i')
.help(translate!("expand-help-initial"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::TABS)
.long(options::TABS)
.short('t')
.value_name("N, LIST")
.action(ArgAction::Append)
.help(translate!("expand-help-tabs")),
)
.arg(
Arg::new(options::NO_UTF8)
.long(options::NO_UTF8)
.short('U')
.help(translate!("expand-help-no-utf8"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::FILES)
.action(ArgAction::Append)
.hide(true)
.value_hint(clap::ValueHint::FilePath)
.value_parser(clap::value_parser!(OsString)),
)
uucore::clap_localization::configure_localized_command(
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.about(translate!("expand-about"))
.after_help(LONG_HELP)
.override_usage(format_usage(&translate!("expand-usage"))),
)
.infer_long_args(true)
.args_override_self(true)
.arg(
Arg::new(options::INITIAL)
.long(options::INITIAL)
.short('i')
.help(translate!("expand-help-initial"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::TABS)
.long(options::TABS)
.short('t')
.value_name("N, LIST")
.action(ArgAction::Append)
.help(translate!("expand-help-tabs")),
)
.arg(
Arg::new(options::NO_UTF8)
.long(options::NO_UTF8)
.short('U')
.help(translate!("expand-help-no-utf8"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::FILES)
.action(ArgAction::Append)
.hide(true)
.value_hint(clap::ValueHint::FilePath)
.value_parser(clap::value_parser!(OsString)),
)
}
fn open(path: &OsString) -> UResult<BufReader<Box<dyn Read + 'static>>> {

View file

@ -12,7 +12,6 @@ use std::io::{self, Write, stdin, stdout};
use clap::{Arg, ArgAction, Command};
use num_bigint::BigUint;
use num_traits::FromPrimitive;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError, set_exit_code};
use uucore::translate;
@ -80,7 +79,7 @@ fn write_result(
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
// If matches find --exponents flag than variable print_exponents is true and p^e output format will be used.
let print_exponents = matches.get_flag(options::EXPONENTS);

View file

@ -14,7 +14,6 @@ use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::format_usage;
use linebreak::break_lines;
@ -341,7 +340,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
}
let matches = uu_app().get_matches_from_localized(&args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), &args)?;
let files = extract_files(&matches)?;

View file

@ -9,7 +9,6 @@ use clap::{Arg, ArgAction, Command};
use std::fs::File;
use std::io::{BufRead, BufReader, Read, Write, stdin, stdout};
use std::path::Path;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage;
@ -32,7 +31,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy();
let (args, obs_width) = handle_obsolete(&args[..]);
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let bytes = matches.get_flag(options::BYTES);
let spaces = matches.get_flag(options::SPACES);

View file

@ -14,7 +14,6 @@ use uucore::{
};
use clap::{Arg, ArgAction, Command};
use uucore::LocalizedCommand;
use uucore::translate;
mod options {
@ -48,7 +47,7 @@ fn infallible_gid2grp(gid: &u32) -> String {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let users: Vec<String> = matches
.get_many::<String>(options::USERS)

View file

@ -15,7 +15,6 @@ use std::io::{BufReader, Read, stdin};
use std::iter;
use std::num::ParseIntError;
use std::path::Path;
use uucore::LocalizedCommand;
use uucore::checksum::ChecksumError;
use uucore::checksum::ChecksumOptions;
use uucore::checksum::ChecksumVerbose;
@ -182,7 +181,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
// causes "error: " to be printed twice (once from crash!() and once from clap). With
// the current setup, the name of the utility is not printed, but I think this is at
// least somewhat better from a user's perspective.
let matches = command.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(command, args)?;
let input_length: Option<&usize> = if binary_name == "b2sum" {
matches.get_one::<usize>(options::LENGTH)

View file

@ -14,7 +14,6 @@ use std::num::TryFromIntError;
#[cfg(unix)]
use std::os::fd::{AsRawFd, FromRawFd};
use thiserror::Error;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult};
use uucore::line_ending::LineEnding;
@ -555,7 +554,7 @@ fn uu_head(options: &HeadOptions) -> UResult<()> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args: Vec<_> = arg_iterate(args)?.collect();
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let options = HeadOptions::get_from(&matches).map_err(HeadError::MatchOption)?;
uu_head(&options)
}

View file

@ -9,12 +9,11 @@ use clap::Command;
use libc::{c_long, gethostid};
use uucore::{error::UResult, format_usage};
use uucore::LocalizedCommand;
use uucore::translate;
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uu_app().get_matches_from_localized(args);
uucore::clap_localization::handle_clap_result(uu_app(), args)?;
hostid();
Ok(())
}

View file

@ -12,7 +12,6 @@ use std::{collections::hash_set::HashSet, ffi::OsString};
use clap::builder::ValueParser;
use clap::{Arg, ArgAction, ArgMatches, Command};
use uucore::LocalizedCommand;
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
use dns_lookup::lookup_host;
@ -61,7 +60,7 @@ mod wsa {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
#[cfg(windows)]
let _handle = wsa::start().map_err_context(|| translate!("hostname-error-winsock"))?;

View file

@ -44,7 +44,6 @@ use uucore::libc::{getlogin, uid_t};
use uucore::line_ending::LineEnding;
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::process::{getegid, geteuid, getgid, getuid};
use uucore::{format_usage, show_error};
@ -120,9 +119,7 @@ struct State {
#[uucore::main]
#[allow(clippy::cognitive_complexity)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
.after_help(translate!("id-after-help"))
.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let users: Vec<String> = matches
.get_many::<String>(options::ARG_USERS)
@ -355,6 +352,7 @@ pub fn uu_app() -> Command {
.override_usage(format_usage(&translate!("id-usage")))
.infer_long_args(true)
.args_override_self(true)
.after_help(translate!("id-after-help"))
.arg(
Arg::new(options::OPT_AUDIT)
.short('A')

View file

@ -17,7 +17,6 @@ use std::fs::{self, metadata};
use std::path::{MAIN_SEPARATOR, Path, PathBuf};
use std::process;
use thiserror::Error;
use uucore::LocalizedCommand;
use uucore::backup_control::{self, BackupMode};
use uucore::buf_copy::copy_stream;
use uucore::display::Quotable;
@ -167,7 +166,7 @@ static ARG_FILES: &str = "files";
///
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let paths: Vec<OsString> = matches
.get_many::<OsString>(ARG_FILES)

View file

@ -16,7 +16,6 @@ use std::num::IntErrorKind;
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
use thiserror::Error;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code};
use uucore::format_usage;
@ -823,7 +822,7 @@ fn parse_settings(matches: &clap::ArgMatches) -> UResult<Settings> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let settings = parse_settings(&matches)?;

View file

@ -13,7 +13,6 @@ use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::signals::{ALL_SIGNALS, signal_by_name_or_value, signal_name_by_value};
use uucore::{format_usage, show};
@ -41,7 +40,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut args = args.collect_ignore();
let obs_signal = handle_obsolete(&mut args);
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let mode = if matches.get_flag(options::TABLE) {
Mode::Table

View file

@ -8,7 +8,6 @@ use clap::{Arg, Command};
use std::ffi::OsString;
use std::fs::hard_link;
use std::path::Path;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult};
use uucore::format_usage;
@ -20,7 +19,7 @@ pub mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let files: Vec<_> = matches
.get_many::<OsString>(options::FILES)
.unwrap_or_default()

View file

@ -23,7 +23,6 @@ use std::os::unix::fs::symlink;
#[cfg(windows)]
use std::os::windows::fs::{symlink_dir, symlink_file};
use std::path::{Path, PathBuf};
use uucore::LocalizedCommand;
use uucore::backup_control::{self, BackupMode};
use uucore::fs::{MissingHandling, ResolveMode, canonicalize};
@ -89,15 +88,7 @@ static ARG_FILES: &str = "files";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let after_help = format!(
"{}\n\n{}",
translate!("ln-after-help"),
backup_control::BACKUP_CONTROL_LONG_HELP
);
let matches = uu_app()
.after_help(after_help)
.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
/* the list of files */
@ -142,12 +133,19 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
let after_help = format!(
"{}\n\n{}",
translate!("ln-after-help"),
backup_control::BACKUP_CONTROL_LONG_HELP
);
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("ln-about"))
.override_usage(format_usage(&translate!("ln-usage")))
.infer_long_args(true)
.after_help(after_help)
.arg(backup_control::arguments::backup())
.arg(backup_control::arguments::backup_no_args())
/*.arg(

View file

@ -7,7 +7,6 @@
use clap::Command;
use std::ffi::CStr;
use uucore::LocalizedCommand;
use uucore::translate;
use uucore::{error::UResult, show_error};
@ -24,7 +23,7 @@ fn get_userlogin() -> Option<String> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let _ = uu_app().get_matches_from_localized(args);
let _ = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
match get_userlogin() {
Some(userlogin) => println!("{userlogin}"),

File diff suppressed because it is too large Load diff

View file

@ -15,7 +15,6 @@ use uucore::error::FromIo;
use uucore::error::{UResult, USimpleError};
use uucore::translate;
use uucore::LocalizedCommand;
#[cfg(not(windows))]
use uucore::mode;
use uucore::{display::Quotable, fs::dir_strip_dot_for_creation};
@ -80,9 +79,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// Linux-specific options, not implemented
// opts.optflag("Z", "context", "set SELinux security context" +
// " of each created directory to CTX"),
let matches = uu_app()
.after_help(translate!("mkdir-after-help"))
.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let dirs = matches
.get_many::<OsString>(options::DIRS)
@ -116,6 +113,7 @@ pub fn uu_app() -> Command {
.about(translate!("mkdir-about"))
.override_usage(format_usage(&translate!("mkdir-usage")))
.infer_long_args(true)
.after_help(translate!("mkdir-after-help"))
.arg(
Arg::new(options::MODE)
.short('m')

View file

@ -12,7 +12,6 @@ use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::{format_usage, show};
mod options {
@ -24,7 +23,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let mode = calculate_mode(matches.get_one::<String>(options::MODE))
.map_err(|e| USimpleError::new(1, translate!("mkfifo-error-invalid-mode", "error" => e)))?;

View file

@ -10,7 +10,6 @@ use libc::{S_IFBLK, S_IFCHR, S_IFIFO, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOT
use libc::{dev_t, mode_t};
use std::ffi::CString;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError, set_exit_code};
use uucore::format_usage;
@ -112,7 +111,7 @@ fn mknod(file_name: &str, config: Config) -> i32 {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let file_type = matches.get_one::<FileType>("type").unwrap();

View file

@ -343,7 +343,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Err(e) => {
use uucore::clap_localization::handle_clap_error_with_exit_code;
if e.kind() == clap::error::ErrorKind::UnknownArgument {
handle_clap_error_with_exit_code(e, uucore::util_name(), 1);
handle_clap_error_with_exit_code(e, 1);
}
if e.kind() == clap::error::ErrorKind::TooManyValues
&& e.context().any(|(kind, val)| {

View file

@ -27,7 +27,6 @@ use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::format_usage;
use uucore::{display::Quotable, show};
use uucore::LocalizedCommand;
use uucore::translate;
#[derive(Debug)]
@ -153,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
print!("\r");
println!("{panic_info}");
}));
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let mut options = Options::from(&matches);
if let Some(files) = matches.get_many::<OsString>(options::FILES) {
let length = files.len();

View file

@ -52,7 +52,6 @@ use uucore::update_control;
// These are exposed for projects (e.g. nushell) that want to create an `Options` value, which
// requires these enums
use uucore::LocalizedCommand;
pub use uucore::{backup_control::BackupMode, update_control::UpdateMode};
use uucore::{format_usage, prompt_yes, show};
@ -153,7 +152,7 @@ static OPT_SELINUX: &str = "selinux";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let files: Vec<OsString> = matches
.get_many::<OsString>(ARG_FILES)
@ -166,7 +165,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
ErrorKind::TooFewValues,
translate!("mv-error-insufficient-arguments", "arg_files" => ARG_FILES),
);
uucore::clap_localization::handle_clap_error_with_exit_code(err, uucore::util_name(), 1);
uucore::clap_localization::handle_clap_error_with_exit_code(err, 1);
}
let overwrite_mode = determine_overwrite_mode(&matches);

View file

@ -13,7 +13,7 @@ use std::ptr;
use uucore::translate;
use uucore::{
error::{UClapError, UResult, USimpleError, UUsageError, set_exit_code},
error::{UResult, USimpleError, UUsageError, set_exit_code},
format_usage, show_error,
};
@ -103,7 +103,8 @@ fn standardize_nice_args(mut args: impl uucore::Args) -> impl uucore::Args {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = standardize_nice_args(args);
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
let matches =
uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 125)?;
nix::errno::Errno::clear();
let mut niceness = unsafe { libc::getpriority(PRIO_PROCESS, 0) };

View file

@ -9,7 +9,7 @@ use std::fs::File;
use std::io::{BufRead, BufReader, Read, stdin};
use std::path::Path;
use uucore::error::{FromIo, UResult, USimpleError, set_exit_code};
use uucore::{LocalizedCommand, format_usage, show_error, translate};
use uucore::{format_usage, show_error, translate};
mod helper;
@ -186,7 +186,7 @@ pub mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let mut settings = Settings::default();

View file

@ -16,7 +16,7 @@ use std::os::unix::prelude::*;
use std::path::{Path, PathBuf};
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::{UClapError, UError, UResult, set_exit_code};
use uucore::error::{UError, UResult, set_exit_code};
use uucore::translate;
use uucore::{format_usage, show_error};
@ -57,7 +57,8 @@ impl UError for NohupError {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
let matches =
uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 125)?;
replace_fds()?;

View file

@ -7,7 +7,6 @@
use clap::{Arg, ArgAction, Command};
use std::{env, thread};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
@ -27,7 +26,7 @@ static OPT_IGNORE: &str = "ignore";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let ignore = match matches.get_one::<String>(OPT_IGNORE) {
Some(numstr) => match numstr.trim().parse::<usize>() {

View file

@ -13,7 +13,6 @@ use std::result::Result as StdResult;
use std::str::FromStr;
use units::{IEC_BASES, SI_BASES};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::UResult;
use uucore::translate;
@ -255,7 +254,7 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?;

View file

@ -46,7 +46,6 @@ use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::parser::parse_size::ParseSizeError;
use uucore::parser::shortcut_value_parser::ShortcutValueParser;
use uucore::{format_usage, show_error, show_warning};
@ -221,7 +220,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let clap_opts = uu_app();
let clap_matches = clap_opts.get_matches_from_localized(&args);
let clap_matches = uucore::clap_localization::handle_clap_result(clap_opts, &args)?;
let od_options = OdOptions::new(&clap_matches, &args)?;

View file

@ -12,7 +12,6 @@ use std::iter::Cycle;
use std::path::Path;
use std::rc::Rc;
use std::slice::Iter;
use uucore::LocalizedCommand;
use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
use uucore::line_ending::LineEnding;
@ -27,7 +26,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let serial = matches.get_flag(options::SERIAL);
let delimiters = matches.get_one::<String>(options::DELIMITER).unwrap();

View file

@ -9,7 +9,6 @@ use clap::{Arg, ArgAction, Command};
use std::ffi::OsString;
use std::fs;
use std::io::{ErrorKind, Write};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{UResult, UUsageError, set_exit_code};
use uucore::format_usage;
@ -36,7 +35,7 @@ const POSIX_NAME_MAX: usize = 14;
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
// set working mode
let is_posix = matches.get_flag(options::POSIX);

View file

@ -34,12 +34,12 @@ pub fn uu_app() -> Command {
#[cfg(target_env = "musl")]
let about = translate!("pinky-about") + &translate!("pinky-about-musl-warning");
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(about)
.override_usage(format_usage(&translate!("pinky-usage")))
.infer_long_args(true)
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd)
.disable_help_flag(true)
.arg(
Arg::new(options::LONG_FORMAT)

View file

@ -5,12 +5,11 @@
// Specific implementation for OpenBSD: tool unsupported (utmpx not supported)
use crate::uu_app;
use uucore::LocalizedCommand;
use uucore::error::UResult;
use uucore::translate;
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let _matches = uu_app().get_matches_from_localized(args);
let _matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
println!("{}", translate!("pinky-unsupported-openbsd"));
Ok(())
}

View file

@ -9,7 +9,6 @@ use crate::Capitalize;
use crate::options;
use crate::uu_app;
use uucore::LocalizedCommand;
use uucore::entries::{Locate, Passwd};
use uucore::error::{FromIo, UResult};
use uucore::libc::S_IWGRP;
@ -33,9 +32,8 @@ fn get_long_usage() -> String {
}
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
.after_help(get_long_usage())
.get_matches_from_localized(args);
let matches =
uucore::clap_localization::handle_clap_result(uu_app().after_help(get_long_usage()), args)?;
let users: Vec<String> = matches
.get_many::<String>(options::USER)

View file

@ -16,7 +16,6 @@ use std::os::unix::fs::FileTypeExt;
use std::time::SystemTime;
use thiserror::Error;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::UResult;
use uucore::format_usage;
@ -318,7 +317,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let opt_args = recreate_arguments(&args);
let command = uu_app();
let matches = command.get_matches_from_mut_localized(opt_args);
let matches = uucore::clap_localization::handle_clap_result(command, opt_args)?;
let mut files = matches
.get_many::<String>(options::FILES)

View file

@ -14,10 +14,7 @@ static ARG_VARIABLES: &str = "variables";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args).unwrap_or_else(|e| {
use uucore::clap_localization::handle_clap_error_with_exit_code;
handle_clap_error_with_exit_code(e, uucore::util_name(), 2)
});
let matches = uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 2)?;
let variables: Vec<String> = matches
.get_many::<String>(ARG_VARIABLES)
@ -55,12 +52,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("printenv-about"))
.override_usage(format_usage(&translate!("printenv-usage")))
.infer_long_args(true)
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd)
.arg(
Arg::new(OPT_NULL)
.short('0')

View file

@ -6,7 +6,6 @@ use clap::{Arg, ArgAction, Command};
use std::ffi::OsString;
use std::io::stdout;
use std::ops::ControlFlow;
use uucore::LocalizedCommand;
use uucore::error::{UResult, UUsageError};
use uucore::format::{FormatArgument, FormatArguments, FormatItem, parse_spec_and_escape};
use uucore::translate;
@ -22,7 +21,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let format = matches
.get_one::<OsString>(options::FORMAT)

View file

@ -17,7 +17,6 @@ use std::path::Path;
use clap::{Arg, ArgAction, Command};
use regex::Regex;
use thiserror::Error;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, UUsageError};
use uucore::format_usage;
@ -731,7 +730,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let config = get_config(&matches)?;
let input_files;

View file

@ -13,7 +13,6 @@ use uucore::format_usage;
use uucore::display::println_verbatim;
use uucore::error::{FromIo, UResult};
use uucore::LocalizedCommand;
use uucore::translate;
const OPT_LOGICAL: &str = "logical";
const OPT_PHYSICAL: &str = "physical";
@ -110,7 +109,7 @@ fn logical_path() -> io::Result<PathBuf> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
// if POSIXLY_CORRECT is set, we want to a logical resolution.
// This produces a different output when doing mkdir -p a/b && ln -s a/b c && cd c && pwd
// We should get c in this case instead of a/b at the end of the path

View file

@ -10,7 +10,6 @@ use std::ffi::OsString;
use std::fs;
use std::io::{Write, stdout};
use std::path::{Path, PathBuf};
use uucore::LocalizedCommand;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::fs::{MissingHandling, ResolveMode, canonicalize};
use uucore::line_ending::LineEnding;
@ -30,7 +29,7 @@ const ARG_FILES: &str = "files";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let mut no_trailing_delimiter = matches.get_flag(OPT_NO_NEWLINE);
let use_zero = matches.get_flag(OPT_ZERO);

View file

@ -18,7 +18,7 @@ use uucore::fs::make_path_relative_to;
use uucore::translate;
use uucore::{
display::{Quotable, print_verbatim},
error::{FromIo, UClapError, UResult},
error::{FromIo, UResult},
format_usage,
fs::{MissingHandling, ResolveMode, canonicalize},
line_ending::LineEnding,
@ -72,7 +72,7 @@ impl ValueParserFactory for NonEmptyOsStringParser {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args).with_exit_code(1)?;
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
/* the list of files */

View file

@ -23,7 +23,6 @@ use uucore::error::{FromIo, UError, UResult};
use uucore::parser::shortcut_value_parser::ShortcutValueParser;
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::{format_usage, os_str_as_bytes, prompt_yes, show_error};
#[derive(Debug, Error)]
@ -144,7 +143,7 @@ static ARG_FILES: &str = "files";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let files: Vec<_> = matches
.get_many::<OsString>(ARG_FILES)

View file

@ -15,7 +15,6 @@ use uucore::display::Quotable;
use uucore::error::{UResult, set_exit_code, strip_errno};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::{format_usage, show_error, util_name};
static OPT_IGNORE_FAIL_NON_EMPTY: &str = "ignore-fail-on-non-empty";
@ -26,7 +25,7 @@ static ARG_DIRS: &str = "dirs";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let opts = Opts {
ignore: matches.get_flag(OPT_IGNORE_FAIL_NON_EMPTY),

View file

@ -6,7 +6,7 @@
#![cfg(target_os = "linux")]
use clap::builder::ValueParser;
use uucore::error::{UClapError, UError, UResult};
use uucore::error::{UError, UResult};
use uucore::translate;
use clap::{Arg, ArgAction, Command};
@ -37,12 +37,7 @@ pub mod options {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let config = uu_app();
let options = match parse_command_line(config, args) {
Ok(r) => r,
Err(r) => {
return Err(r);
}
};
let options = parse_command_line(config, args)?;
match &options.mode {
CommandLineMode::Print => print_current_context().map_err(|e| RunconError::new(e).into()),
@ -85,13 +80,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("runcon-about"))
.after_help(translate!("runcon-after-help"))
.override_usage(format_usage(&translate!("runcon-usage")))
.infer_long_args(true)
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd)
.arg(
Arg::new(options::COMPUTE)
.short('c')
@ -185,7 +180,7 @@ struct Options {
}
fn parse_command_line(config: Command, args: impl uucore::Args) -> UResult<Options> {
let matches = config.try_get_matches_from(args).with_exit_code(125)?;
let matches = uucore::clap_localization::handle_clap_result_with_exit_code(config, args, 125)?;
let compute_transition_context = matches.get_flag(options::COMPUTE);

View file

@ -92,7 +92,8 @@ fn select_precision(
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(split_short_args_with_value(args))?;
let matches =
uucore::clap_localization::handle_clap_result(uu_app(), split_short_args_with_value(args))?;
let numbers_option = matches.get_many::<String>(ARG_NUMBERS);

View file

@ -15,7 +15,6 @@ use std::io::{self, Read, Seek, Write};
#[cfg(unix)]
use std::os::unix::prelude::PermissionsExt;
use std::path::{Path, PathBuf};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::parser::parse_size::parse_size_u64;
@ -240,7 +239,7 @@ impl<'a> BytesWriter<'a> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
if !matches.contains_id(options::FILE) {
return Err(UUsageError::new(

View file

@ -17,7 +17,6 @@ use std::io::{BufWriter, Error, Read, Write, stdin, stdout};
use std::ops::RangeInclusive;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use uucore::LocalizedCommand;
use uucore::display::{OsWrite, Quotable};
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::format_usage;
@ -52,7 +51,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let mode = if matches.get_flag(options::ECHO) {
Mode::Echo(

View file

@ -6,7 +6,6 @@
use clap::{Arg, ArgAction, Command};
use std::thread;
use std::time::Duration;
use uucore::LocalizedCommand;
use uucore::translate;
use uucore::{
error::{UResult, USimpleError, UUsageError},
@ -21,7 +20,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let numbers = matches
.get_many::<String>(options::NUMBER)

View file

@ -1042,19 +1042,7 @@ const STDIN_FILE: &str = "-";
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut settings = GlobalSettings::default();
let matches = match uu_app().try_get_matches_from(args) {
Ok(t) => t,
Err(e) => {
// not all clap "Errors" are because of a failure to parse arguments.
// "--version" also causes an Error to be returned, but we should not print to stderr
// nor return with a non-zero exit code in this case (we should print to stdout and return 0).
// This logic is similar to the code in clap, but we return 2 as the exit code in case of real failure
// (clap returns 1).
use uucore::clap_localization::handle_clap_error_with_exit_code;
// Always use the localization handler for proper error and help handling
handle_clap_error_with_exit_code(e, uucore::util_name(), 2);
}
};
let matches = uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 2)?;
// Prevent -o/--output to be specified multiple times
if matches
@ -1338,250 +1326,251 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.about(translate!("sort-about"))
.after_help(translate!("sort-after-help"))
.override_usage(format_usage(&translate!("sort-usage")))
.help_template(uucore::localized_help_template(uucore::util_name()))
.infer_long_args(true)
.disable_help_flag(true)
.disable_version_flag(true)
.args_override_self(true)
.arg(
Arg::new(options::HELP)
.long(options::HELP)
.help(translate!("sort-help-help"))
.action(ArgAction::Help),
)
.arg(
Arg::new(options::VERSION)
.long(options::VERSION)
.help(translate!("sort-help-version"))
.action(ArgAction::Version),
)
.arg(
Arg::new(options::modes::SORT)
.long(options::modes::SORT)
.value_parser(ShortcutValueParser::new([
"general-numeric",
"human-numeric",
"month",
"numeric",
"version",
"random",
]))
.conflicts_with_all(options::modes::ALL_SORT_MODES),
)
.arg(make_sort_mode_arg(
options::modes::HUMAN_NUMERIC,
'h',
translate!("sort-help-human-numeric"),
))
.arg(make_sort_mode_arg(
options::modes::MONTH,
'M',
translate!("sort-help-month"),
))
.arg(make_sort_mode_arg(
options::modes::NUMERIC,
'n',
translate!("sort-help-numeric"),
))
.arg(make_sort_mode_arg(
options::modes::GENERAL_NUMERIC,
'g',
translate!("sort-help-general-numeric"),
))
.arg(make_sort_mode_arg(
options::modes::VERSION,
'V',
translate!("sort-help-version-sort"),
))
.arg(make_sort_mode_arg(
options::modes::RANDOM,
'R',
translate!("sort-help-random"),
))
.arg(
Arg::new(options::DICTIONARY_ORDER)
.short('d')
.long(options::DICTIONARY_ORDER)
.help(translate!("sort-help-dictionary-order"))
.conflicts_with_all([
options::modes::NUMERIC,
options::modes::GENERAL_NUMERIC,
options::modes::HUMAN_NUMERIC,
options::modes::MONTH,
])
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::MERGE)
.short('m')
.long(options::MERGE)
.help(translate!("sort-help-merge"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::check::CHECK)
.short('c')
.long(options::check::CHECK)
.require_equals(true)
.num_args(0..)
.value_parser(ShortcutValueParser::new([
options::check::SILENT,
options::check::QUIET,
options::check::DIAGNOSE_FIRST,
]))
.conflicts_with_all([options::OUTPUT, options::check::CHECK_SILENT])
.help(translate!("sort-help-check")),
)
.arg(
Arg::new(options::check::CHECK_SILENT)
.short('C')
.long(options::check::CHECK_SILENT)
.conflicts_with_all([options::OUTPUT, options::check::CHECK])
.help(translate!("sort-help-check-silent"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::IGNORE_CASE)
.short('f')
.long(options::IGNORE_CASE)
.help(translate!("sort-help-ignore-case"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::IGNORE_NONPRINTING)
.short('i')
.long(options::IGNORE_NONPRINTING)
.help(translate!("sort-help-ignore-nonprinting"))
.conflicts_with_all([
options::modes::NUMERIC,
options::modes::GENERAL_NUMERIC,
options::modes::HUMAN_NUMERIC,
options::modes::MONTH,
])
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::IGNORE_LEADING_BLANKS)
.short('b')
.long(options::IGNORE_LEADING_BLANKS)
.help(translate!("sort-help-ignore-leading-blanks"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::OUTPUT)
.short('o')
.long(options::OUTPUT)
.help(translate!("sort-help-output"))
.value_parser(ValueParser::os_string())
.value_name("FILENAME")
.value_hint(clap::ValueHint::FilePath)
.num_args(1)
.allow_hyphen_values(true)
// To detect multiple occurrences and raise an error
.action(ArgAction::Append),
)
.arg(
Arg::new(options::REVERSE)
.short('r')
.long(options::REVERSE)
.help(translate!("sort-help-reverse"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::STABLE)
.short('s')
.long(options::STABLE)
.help(translate!("sort-help-stable"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::UNIQUE)
.short('u')
.long(options::UNIQUE)
.help(translate!("sort-help-unique"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::KEY)
.short('k')
.long(options::KEY)
.help(translate!("sort-help-key"))
.action(ArgAction::Append)
.num_args(1),
)
.arg(
Arg::new(options::SEPARATOR)
.short('t')
.long(options::SEPARATOR)
.help(translate!("sort-help-separator"))
.value_parser(ValueParser::os_string()),
)
.arg(
Arg::new(options::ZERO_TERMINATED)
.short('z')
.long(options::ZERO_TERMINATED)
.help(translate!("sort-help-zero-terminated"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::PARALLEL)
.long(options::PARALLEL)
.help(translate!("sort-help-parallel"))
.value_name("NUM_THREADS"),
)
.arg(
Arg::new(options::BUF_SIZE)
.short('S')
.long(options::BUF_SIZE)
.help(translate!("sort-help-buf-size"))
.value_name("SIZE"),
)
.arg(
Arg::new(options::TMP_DIR)
.short('T')
.long(options::TMP_DIR)
.help(translate!("sort-help-tmp-dir"))
.value_name("DIR")
.value_hint(clap::ValueHint::DirPath),
)
.arg(
Arg::new(options::COMPRESS_PROG)
.long(options::COMPRESS_PROG)
.help(translate!("sort-help-compress-prog"))
.value_name("PROG")
.value_hint(clap::ValueHint::CommandName),
)
.arg(
Arg::new(options::BATCH_SIZE)
.long(options::BATCH_SIZE)
.help(translate!("sort-help-batch-size"))
.value_name("N_MERGE"),
)
.arg(
Arg::new(options::FILES0_FROM)
.long(options::FILES0_FROM)
.help(translate!("sort-help-files0-from"))
.value_name("NUL_FILE")
.value_parser(ValueParser::os_string())
.value_hint(clap::ValueHint::FilePath),
)
.arg(
Arg::new(options::DEBUG)
.long(options::DEBUG)
.help(translate!("sort-help-debug"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::FILES)
.action(ArgAction::Append)
.value_parser(ValueParser::os_string())
.value_hint(clap::ValueHint::FilePath),
)
uucore::clap_localization::configure_localized_command(
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.about(translate!("sort-about"))
.after_help(translate!("sort-after-help"))
.override_usage(format_usage(&translate!("sort-usage"))),
)
.infer_long_args(true)
.disable_help_flag(true)
.disable_version_flag(true)
.args_override_self(true)
.arg(
Arg::new(options::HELP)
.long(options::HELP)
.help(translate!("sort-help-help"))
.action(ArgAction::Help),
)
.arg(
Arg::new(options::VERSION)
.long(options::VERSION)
.help(translate!("sort-help-version"))
.action(ArgAction::Version),
)
.arg(
Arg::new(options::modes::SORT)
.long(options::modes::SORT)
.value_parser(ShortcutValueParser::new([
"general-numeric",
"human-numeric",
"month",
"numeric",
"version",
"random",
]))
.conflicts_with_all(options::modes::ALL_SORT_MODES),
)
.arg(make_sort_mode_arg(
options::modes::HUMAN_NUMERIC,
'h',
translate!("sort-help-human-numeric"),
))
.arg(make_sort_mode_arg(
options::modes::MONTH,
'M',
translate!("sort-help-month"),
))
.arg(make_sort_mode_arg(
options::modes::NUMERIC,
'n',
translate!("sort-help-numeric"),
))
.arg(make_sort_mode_arg(
options::modes::GENERAL_NUMERIC,
'g',
translate!("sort-help-general-numeric"),
))
.arg(make_sort_mode_arg(
options::modes::VERSION,
'V',
translate!("sort-help-version-sort"),
))
.arg(make_sort_mode_arg(
options::modes::RANDOM,
'R',
translate!("sort-help-random"),
))
.arg(
Arg::new(options::DICTIONARY_ORDER)
.short('d')
.long(options::DICTIONARY_ORDER)
.help(translate!("sort-help-dictionary-order"))
.conflicts_with_all([
options::modes::NUMERIC,
options::modes::GENERAL_NUMERIC,
options::modes::HUMAN_NUMERIC,
options::modes::MONTH,
])
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::MERGE)
.short('m')
.long(options::MERGE)
.help(translate!("sort-help-merge"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::check::CHECK)
.short('c')
.long(options::check::CHECK)
.require_equals(true)
.num_args(0..)
.value_parser(ShortcutValueParser::new([
options::check::SILENT,
options::check::QUIET,
options::check::DIAGNOSE_FIRST,
]))
.conflicts_with_all([options::OUTPUT, options::check::CHECK_SILENT])
.help(translate!("sort-help-check")),
)
.arg(
Arg::new(options::check::CHECK_SILENT)
.short('C')
.long(options::check::CHECK_SILENT)
.conflicts_with_all([options::OUTPUT, options::check::CHECK])
.help(translate!("sort-help-check-silent"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::IGNORE_CASE)
.short('f')
.long(options::IGNORE_CASE)
.help(translate!("sort-help-ignore-case"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::IGNORE_NONPRINTING)
.short('i')
.long(options::IGNORE_NONPRINTING)
.help(translate!("sort-help-ignore-nonprinting"))
.conflicts_with_all([
options::modes::NUMERIC,
options::modes::GENERAL_NUMERIC,
options::modes::HUMAN_NUMERIC,
options::modes::MONTH,
])
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::IGNORE_LEADING_BLANKS)
.short('b')
.long(options::IGNORE_LEADING_BLANKS)
.help(translate!("sort-help-ignore-leading-blanks"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::OUTPUT)
.short('o')
.long(options::OUTPUT)
.help(translate!("sort-help-output"))
.value_parser(ValueParser::os_string())
.value_name("FILENAME")
.value_hint(clap::ValueHint::FilePath)
.num_args(1)
.allow_hyphen_values(true)
// To detect multiple occurrences and raise an error
.action(ArgAction::Append),
)
.arg(
Arg::new(options::REVERSE)
.short('r')
.long(options::REVERSE)
.help(translate!("sort-help-reverse"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::STABLE)
.short('s')
.long(options::STABLE)
.help(translate!("sort-help-stable"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::UNIQUE)
.short('u')
.long(options::UNIQUE)
.help(translate!("sort-help-unique"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::KEY)
.short('k')
.long(options::KEY)
.help(translate!("sort-help-key"))
.action(ArgAction::Append)
.num_args(1),
)
.arg(
Arg::new(options::SEPARATOR)
.short('t')
.long(options::SEPARATOR)
.help(translate!("sort-help-separator"))
.value_parser(ValueParser::os_string()),
)
.arg(
Arg::new(options::ZERO_TERMINATED)
.short('z')
.long(options::ZERO_TERMINATED)
.help(translate!("sort-help-zero-terminated"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::PARALLEL)
.long(options::PARALLEL)
.help(translate!("sort-help-parallel"))
.value_name("NUM_THREADS"),
)
.arg(
Arg::new(options::BUF_SIZE)
.short('S')
.long(options::BUF_SIZE)
.help(translate!("sort-help-buf-size"))
.value_name("SIZE"),
)
.arg(
Arg::new(options::TMP_DIR)
.short('T')
.long(options::TMP_DIR)
.help(translate!("sort-help-tmp-dir"))
.value_name("DIR")
.value_hint(clap::ValueHint::DirPath),
)
.arg(
Arg::new(options::COMPRESS_PROG)
.long(options::COMPRESS_PROG)
.help(translate!("sort-help-compress-prog"))
.value_name("PROG")
.value_hint(clap::ValueHint::CommandName),
)
.arg(
Arg::new(options::BATCH_SIZE)
.long(options::BATCH_SIZE)
.help(translate!("sort-help-batch-size"))
.value_name("N_MERGE"),
)
.arg(
Arg::new(options::FILES0_FROM)
.long(options::FILES0_FROM)
.help(translate!("sort-help-files0-from"))
.value_name("NUL_FILE")
.value_parser(ValueParser::os_string())
.value_hint(clap::ValueHint::FilePath),
)
.arg(
Arg::new(options::DEBUG)
.long(options::DEBUG)
.help(translate!("sort-help-debug"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::FILES)
.action(ArgAction::Append)
.value_parser(ValueParser::os_string())
.value_hint(clap::ValueHint::FilePath),
)
}
fn exec(

View file

@ -26,7 +26,6 @@ use uucore::translate;
use uucore::parser::parse_size::parse_size_u64;
use uucore::LocalizedCommand;
use uucore::format_usage;
use uucore::uio_error;
@ -52,7 +51,7 @@ static ARG_PREFIX: &str = "prefix";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let (args, obs_lines) = handle_obsolete(args);
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
match Settings::from(&matches, obs_lines.as_deref()) {
Ok(settings) => split(&settings),

View file

@ -27,7 +27,6 @@ use std::path::Path;
use std::{env, fs};
use thiserror::Error;
use uucore::LocalizedCommand;
use uucore::time::{FormatSystemTimeFallback, format_system_time, system_time_to_sec};
#[derive(Debug, Error)]
@ -1219,9 +1218,7 @@ impl Stater {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
.after_help(translate!("stat-after-help"))
.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let stater = Stater::new(&matches)?;
let exit_status = stater.exec();
@ -1237,6 +1234,7 @@ pub fn uu_app() -> Command {
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("stat-about"))
.after_help(translate!("stat-after-help"))
.override_usage(format_usage(&translate!("stat-usage")))
.infer_long_args(true)
.arg(

View file

@ -13,7 +13,7 @@ use std::process;
use tempfile::TempDir;
use tempfile::tempdir;
use thiserror::Error;
use uucore::error::{FromIo, UClapError, UResult, USimpleError, UUsageError};
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::format_usage;
use uucore::parser::parse_size::parse_size_u64;
use uucore::translate;
@ -179,7 +179,8 @@ fn get_preload_env(_tmp_dir: &TempDir) -> UResult<(String, PathBuf)> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
let matches =
uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 125)?;
let options =
ProgramOptions::try_from(&matches).map_err(|e| UUsageError::new(125, e.to_string()))?;

View file

@ -29,7 +29,6 @@ use std::num::IntErrorKind;
use std::os::fd::{AsFd, BorrowedFd};
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{AsRawFd, RawFd};
use uucore::LocalizedCommand;
use uucore::error::{UError, UResult, USimpleError};
use uucore::format_usage;
use uucore::translate;
@ -243,7 +242,7 @@ ioctl_write_ptr_bad!(
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let opts = Options::from(&matches)?;

View file

@ -14,7 +14,6 @@ use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::{format_usage, show};
fn bsd_sum(mut reader: impl Read) -> std::io::Result<(usize, u16)> {
@ -99,7 +98,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let files: Vec<OsString> = match matches.get_many::<OsString>(options::FILE) {
Some(v) => v.cloned().collect(),

View file

@ -13,7 +13,6 @@ use nix::fcntl::{OFlag, open};
#[cfg(any(target_os = "linux", target_os = "android"))]
use nix::sys::stat::Mode;
use std::path::Path;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
#[cfg(any(target_os = "linux", target_os = "android"))]
use uucore::error::FromIo;
@ -174,7 +173,7 @@ mod platform {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let files: Vec<String> = matches
.get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect())

View file

@ -21,7 +21,6 @@ use uucore::{format_usage, show};
use crate::error::TacError;
use uucore::LocalizedCommand;
use uucore::translate;
mod options {
@ -33,7 +32,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let before = matches.get_flag(options::BEFORE);
let regex = matches.get_flag(options::REGEX);

View file

@ -18,7 +18,6 @@ use uucore::{format_usage, show_error};
// spell-checker:ignore nopipe
use uucore::LocalizedCommand;
#[cfg(unix)]
use uucore::signals::{enable_pipe_errors, ignore_interrupts};
@ -53,7 +52,7 @@ enum OutputErrorMode {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let append = matches.get_flag(options::APPEND);
let ignore_interrupts = matches.get_flag(options::IGNORE_INTERRUPTS);

View file

@ -15,7 +15,6 @@ use std::ffi::{OsStr, OsString};
use std::fs;
#[cfg(unix)]
use std::os::unix::fs::MetadataExt;
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::format_usage;
@ -51,7 +50,10 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
if binary_name.ends_with('[') {
// If invoked as [ we should recognize --help and --version (but not -h or -v)
if args.len() == 1 && (args[0] == "--help" || args[0] == "--version") {
uu_app().get_matches_from_localized(std::iter::once(program).chain(args.into_iter()));
uucore::clap_localization::handle_clap_result(
uu_app(),
std::iter::once(program).chain(args.into_iter()),
)?;
return Ok(());
}
// If invoked via name '[', matching ']' must be in the last arg

View file

@ -14,7 +14,7 @@ use std::process::{self, Child, Stdio};
use std::sync::atomic::{self, AtomicBool};
use std::time::Duration;
use uucore::display::Quotable;
use uucore::error::{UClapError, UResult, USimpleError, UUsageError};
use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::parser::parse_time;
use uucore::process::ChildExt;
use uucore::translate;
@ -104,7 +104,8 @@ impl Config {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
let matches =
uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 125)?;
let config = Config::from(&matches)?;
timeout(

View file

@ -20,7 +20,6 @@ use std::ffi::OsString;
use std::fs::{self, File};
use std::io::{Error, ErrorKind};
use std::path::{Path, PathBuf};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::parser::shortcut_value_parser::ShortcutValueParser;
@ -187,7 +186,7 @@ fn shr2(s: &str) -> String {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let mut filenames: Vec<&OsString> = matches
.get_many::<OsString>(ARG_FILES)

View file

@ -15,7 +15,6 @@ use operation::{
use simd::process_input;
use std::ffi::OsString;
use std::io::{stdin, stdout};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::fs::is_stdin_directory;
@ -43,7 +42,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
}
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let delete_flag = matches.get_flag(options::DELETE);
let complement_flag = matches.get_flag(options::COMPLEMENT);

View file

@ -84,16 +84,8 @@ pub mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
.after_help(translate!("truncate-after-help"))
.try_get_matches_from(args)
.map_err(|e| {
e.print().expect("Error writing clap::Error");
match e.kind() {
clap::error::ErrorKind::DisplayHelp | clap::error::ErrorKind::DisplayVersion => 0,
_ => 1,
}
})?;
let app = uu_app();
let matches = uucore::clap_localization::handle_clap_result(app, args)?;
let files: Vec<OsString> = matches
.get_many::<OsString>(options::ARG_FILES)
@ -117,12 +109,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("truncate-about"))
.override_usage(format_usage(&translate!("truncate-usage")))
.infer_long_args(true)
.after_help(translate!("truncate-after-help"))
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd)
.arg(
Arg::new(options::IO_BLOCKS)
.short('o')

View file

@ -12,7 +12,6 @@ use uucore::display::Quotable;
use uucore::error::{UError, UResult};
use uucore::{format_usage, show};
use uucore::LocalizedCommand;
use uucore::translate;
mod options {
@ -45,7 +44,7 @@ impl UError for TsortError {}
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let input = matches
.get_one::<OsString>(options::FILE)

View file

@ -18,10 +18,7 @@ mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args).unwrap_or_else(|e| {
use uucore::clap_localization::handle_clap_error_with_exit_code;
handle_clap_error_with_exit_code(e, uucore::util_name(), 2)
});
let matches = uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 2)?;
let silent = matches.get_flag(options::SILENT);
@ -56,18 +53,17 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("tty-about"))
.override_usage(format_usage(&translate!("tty-usage")))
.infer_long_args(true)
.arg(
Arg::new(options::SILENT)
.long(options::SILENT)
.visible_alias("quiet")
.short('s')
.help(translate!("tty-help-silent"))
.action(ArgAction::SetTrue),
)
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd).arg(
Arg::new(options::SILENT)
.long(options::SILENT)
.visible_alias("quiet")
.short('s')
.help(translate!("tty-help-silent"))
.action(ArgAction::SetTrue),
)
}

View file

@ -7,7 +7,6 @@
use clap::{Arg, ArgAction, Command};
use platform_info::*;
use uucore::LocalizedCommand;
use uucore::translate;
use uucore::{
error::{UResult, USimpleError},
@ -121,7 +120,7 @@ pub struct Options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let options = Options {
all: matches.get_flag(options::ALL),

View file

@ -147,7 +147,7 @@ fn expand_shortcuts(args: &[String]) -> Vec<String> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_ignore();
let matches = uu_app().try_get_matches_from(expand_shortcuts(&args))?;
let matches = uucore::clap_localization::handle_clap_result(uu_app(), expand_shortcuts(&args))?;
unexpand(&Options::new(&matches)?)
}

View file

@ -547,9 +547,18 @@ fn map_clap_errors(clap_error: Error) -> Box<dyn UError> {
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let (args, skip_fields_old, skip_chars_old) = handle_obsolete(args);
let matches = uu_app()
.try_get_matches_from(args)
.map_err(map_clap_errors)?;
let matches = match uu_app().try_get_matches_from(args) {
Ok(matches) => matches,
Err(clap_error) => {
if clap_error.exit_code() == 0 {
// Let caller handle help/version
return Err(map_clap_errors(clap_error));
}
// Use ErrorFormatter directly to handle error
let formatter = uucore::clap_localization::ErrorFormatter::new(uucore::util_name());
formatter.print_error_and_exit_with_callback(&clap_error, 1, || {});
}
};
let files = matches.get_many::<OsString>(ARG_FILES);
@ -590,13 +599,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(translate!("uniq-about"))
.override_usage(format_usage(&translate!("uniq-usage")))
.infer_long_args(true)
.after_help(translate!("uniq-after-help"))
.after_help(translate!("uniq-after-help"));
uucore::clap_localization::configure_localized_command(cmd)
.arg(
Arg::new(options::ALL_REPEATED)
.short('D')

View file

@ -9,7 +9,6 @@ use std::path::Path;
use clap::builder::ValueParser;
use clap::{Arg, Command};
use uucore::LocalizedCommand;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult};
use uucore::format_usage;
@ -19,7 +18,7 @@ static OPT_PATH: &str = "FILE";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let path: &Path = matches.get_one::<OsString>(OPT_PATH).unwrap().as_ref();

View file

@ -17,7 +17,6 @@ use uucore::uptime::*;
use clap::{Arg, ArgAction, Command, ValueHint, builder::ValueParser};
use uucore::LocalizedCommand;
use uucore::format_usage;
#[cfg(unix)]
@ -48,7 +47,7 @@ impl UError for UptimeError {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
#[cfg(unix)]
let file_path = matches.get_one::<OsString>(options::PATH);

View file

@ -16,7 +16,6 @@ use uucore::translate;
#[cfg(target_os = "openbsd")]
use utmp_classic::{UtmpEntry, parse_from_path};
use uucore::LocalizedCommand;
#[cfg(not(target_os = "openbsd"))]
use uucore::utmpx::{self, Utmpx};
@ -36,9 +35,7 @@ fn get_long_usage() -> String {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
.after_help(get_long_usage())
.get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let maybe_file: Option<&Path> = matches.get_one::<OsString>(ARG_FILE).map(AsRef::as_ref);
@ -94,6 +91,7 @@ pub fn uu_app() -> Command {
.about(about)
.override_usage(format_usage(&translate!("users-usage")))
.infer_long_args(true)
.after_help(get_long_usage())
.arg(
Arg::new(ARG_FILE)
.num_args(1)

View file

@ -13,7 +13,7 @@ use uucore::quoting_style::QuotingStyle;
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let command = uu_app();
let matches = command.get_matches_from(args);
let matches = uucore::clap_localization::handle_clap_result_with_exit_code(command, args, 2)?;
let mut default_quoting_style = false;
let mut default_format_style = false;

View file

@ -26,7 +26,6 @@ use unicode_width::UnicodeWidthChar;
use utf8::{BufReadDecoder, BufReadDecoderError};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::{
error::{FromIo, UError, UResult},
format_usage,
@ -377,7 +376,7 @@ impl UError for WcError {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from_localized(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
let settings = Settings::new(&matches);
let inputs = Inputs::new(&matches)?;

View file

@ -7,12 +7,11 @@
use crate::uu_app;
use uucore::LocalizedCommand;
use uucore::error::UResult;
use uucore::translate;
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let _matches = uu_app().get_matches_from_localized(args);
let _matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
println!("{}", translate!("who-unsupported-openbsd"));
Ok(())
}

View file

@ -13,7 +13,6 @@ use uucore::error::{FromIo, UResult};
use uucore::libc::{S_IWGRP, STDIN_FILENO, ttyname};
use uucore::translate;
use uucore::LocalizedCommand;
use uucore::utmpx::{self, UtmpxRecord, time};
use std::borrow::Cow;
@ -27,9 +26,8 @@ fn get_long_usage() -> String {
}
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
.after_help(get_long_usage())
.get_matches_from_localized(args);
let matches =
uucore::clap_localization::handle_clap_result(uu_app().after_help(get_long_usage()), args)?;
let files: Vec<String> = matches
.get_many::<String>(options::FILE)

View file

@ -45,12 +45,12 @@ pub fn uu_app() -> Command {
#[cfg(target_env = "musl")]
let about = translate!("who-about") + &translate!("who-about-musl-warning");
Command::new(uucore::util_name())
let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.about(about)
.override_usage(format_usage(&translate!("who-usage")))
.infer_long_args(true)
.infer_long_args(true);
uucore::clap_localization::configure_localized_command(cmd)
.arg(
Arg::new(options::ALL)
.long(options::ALL)

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