diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 64a79a3fd..c6d2283bd 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -81,16 +81,18 @@ fn find_prefixed_util<'a>( } fn setup_localization_or_exit(util_name: &str) { - locale::setup_localization(get_canonical_util_name(util_name)).unwrap_or_else(|err| { - match err { - uucore::locale::LocalizationError::ParseResource { - error: err_msg, - snippet, - } => eprintln!("Localization parse error at {snippet}: {err_msg}"), - other => eprintln!("Could not init the localization system: {other}"), - } - process::exit(99) - }); + locale::setup_localization_with_common(get_canonical_util_name(util_name)).unwrap_or_else( + |err| { + match err { + uucore::locale::LocalizationError::ParseResource { + error: err_msg, + snippet, + } => eprintln!("Localization parse error at {snippet}: {err_msg}"), + other => eprintln!("Could not init the localization system: {other}"), + } + process::exit(99) + }, + ); } #[allow(clippy::cognitive_complexity)] diff --git a/src/uu/arch/src/arch.rs b/src/uu/arch/src/arch.rs index 29ad9d273..cd398a72b 100644 --- a/src/uu/arch/src/arch.rs +++ b/src/uu/arch/src/arch.rs @@ -6,12 +6,13 @@ 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().try_get_matches_from(args)?; + uu_app().try_get_matches_from_localized(args); let uts = PlatformInfo::new().map_err(|_e| USimpleError::new(1, translate!("cannot-get-system")))?; diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index b7d1124ac..e60ea5366 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -9,12 +9,12 @@ use clap::{Arg, ArgAction, Command}; 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, Format, Z85Wrapper, + BASE2LSBF, BASE2MSBF, EncodingWrapper, Format, SupportsFastDecodeAndEncode, Z85Wrapper, for_base_common::{BASE32, BASE32HEX, BASE64, BASE64_NOPAD, BASE64URL, HEXUPPER_PERMISSIVE}, }; -use uucore::encoding::{EncodingWrapper, SupportsFastDecodeAndEncode}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::format_usage; use uucore::translate; @@ -100,7 +100,8 @@ pub fn parse_base_cmd_args( usage: &str, ) -> UResult { let command = base_app(about, usage); - Config::from(&command.try_get_matches_from(args)?) + let matches = command.try_get_matches_from_localized(args); + Config::from(&matches) } pub fn base_app(about: &'static str, usage: &str) -> Command { diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index 255ff6110..802eb4464 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -15,6 +15,7 @@ use uucore::error::{UResult, UUsageError}; use uucore::format_usage; use uucore::line_ending::LineEnding; +use uucore::LocalizedCommand; use uucore::translate; pub mod options { @@ -29,7 +30,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // // Argument parsing // - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO)); diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index c7f975952..22cd38f38 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -22,6 +22,7 @@ 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"))] @@ -230,7 +231,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { libc::signal(libc::SIGPIPE, libc::SIG_DFL); } - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let number_mode = if matches.get_flag(options::NUMBER_NONBLANK) { NumberingMode::NonEmpty diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index ca65cf4a7..de1dc2f64 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -7,6 +7,7 @@ #![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}; @@ -303,7 +304,7 @@ struct Options { } fn parse_command_line(config: Command, args: impl uucore::Args) -> Result { - let matches = config.try_get_matches_from(args)?; + let matches = config.try_get_matches_from_localized(args); let verbose = matches.get_flag(options::VERBOSE); diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index f2d2bd47a..cb540aa7a 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -11,6 +11,7 @@ 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; @@ -112,7 +113,7 @@ 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")) - .try_get_matches_from(args)?; + .try_get_matches_from_localized(args); let changes = matches.get_flag(options::CHANGES); let quiet = matches.get_flag(options::QUIET); diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 6dc28040e..959c23e40 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -20,6 +20,7 @@ use uucore::checksum::{ }; use uucore::translate; +use uucore::LocalizedCommand; use uucore::{ encoding, error::{FromIo, UResult, USimpleError}, @@ -236,7 +237,7 @@ fn handle_tag_text_binary_flags>( #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let check = matches.get_flag(options::CHECK); diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index e55d181d6..81bcab418 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -8,6 +8,7 @@ use std::cmp::Ordering; use std::fs::{File, metadata}; use std::io::{self, BufRead, BufReader, Read, Stdin, stdin}; +use uucore::LocalizedCommand; use uucore::error::{FromIo, UResult, USimpleError}; use uucore::format_usage; use uucore::fs::paths_refer_to_same_file; @@ -280,7 +281,7 @@ fn open_file(name: &str, line_ending: LineEnding) -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED)); let filename1 = matches.get_one::(options::FILE_1).unwrap(); let filename2 = matches.get_one::(options::FILE_2).unwrap(); diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index e826ac3c4..3dee0fe01 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -13,6 +13,7 @@ use std::fs::{self, Metadata, OpenOptions, Permissions}; use std::os::unix::fs::{FileTypeExt, PermissionsExt}; 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; @@ -778,7 +779,7 @@ pub fn uu_app() -> Command { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let options = Options::from_matches(&matches)?; diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index ba58479b2..8c98d37c5 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -25,6 +25,7 @@ mod split_name; use crate::csplit_error::CsplitError; use crate::split_name::SplitName; +use uucore::LocalizedCommand; use uucore::translate; mod options { @@ -604,7 +605,7 @@ where #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); // get the file to split let file_name = matches.get_one::(options::FILE).unwrap(); diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 4bf323507..cf9bfdbe4 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -18,6 +18,7 @@ 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}; @@ -482,7 +483,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }) .collect(); - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let complement = matches.get_flag(options::COMPLEMENT); let only_delimited = matches.get_flag(options::ONLY_DELIMITED); diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 6d5a418c2..1eadd6ce2 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -21,6 +21,7 @@ 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 @@ -111,7 +112,7 @@ impl From<&str> for Rfc3339Format { #[uucore::main] #[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let format = if let Some(form) = matches.get_one::(OPT_FORMAT) { if !form.starts_with('+') { diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 4d77dcfe7..d231da8b1 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -55,6 +55,7 @@ use nix::{ errno::Errno, fcntl::{PosixFadviseAdvice, posix_fadvise}, }; +use uucore::LocalizedCommand; use uucore::display::Quotable; use uucore::error::{FromIo, UResult}; #[cfg(unix)] @@ -1415,7 +1416,7 @@ fn is_fifo(filename: &str) -> bool { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let settings: Settings = Parser::new().parse( matches diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 6c8a1ee7a..2d6d34b23 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -11,6 +11,7 @@ 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}; @@ -406,7 +407,7 @@ impl UError for DfError { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); #[cfg(windows)] { diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index b76d49f67..f6bd9ec40 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -18,6 +18,7 @@ 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 { @@ -120,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().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let files = matches .get_many::(options::FILE) diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 6d7a4a5a5..73618d7e0 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -5,6 +5,7 @@ use clap::{Arg, ArgAction, Command}; use std::path::Path; +use uucore::LocalizedCommand; use uucore::display::print_verbatim; use uucore::error::{UResult, UUsageError}; use uucore::format_usage; @@ -21,7 +22,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app() .after_help(translate!("dirname-after-help")) - .try_get_matches_from(args)?; + .try_get_matches_from_localized(args); let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO)); diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index f39d257de..b43cee530 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -25,6 +25,7 @@ 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; @@ -580,7 +581,7 @@ fn read_files_from(file_name: &str) -> Result, std::io::Error> { #[uucore::main] #[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let summarize = matches.get_flag(options::SUMMARIZE); diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index 776a98536..6dec840da 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -12,6 +12,7 @@ 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; @@ -79,7 +80,7 @@ fn write_result( #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(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); diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 92128f5f1..a0a3f944f 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -24,6 +24,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } if let Err(e) = command.try_get_matches_from_mut(args) { + // For the false command, we don't want to show any error messages for UnknownArgument + // since false should produce no output and just exit with code 1 let error = match e.kind() { clap::error::ErrorKind::DisplayHelp => command.print_help(), clap::error::ErrorKind::DisplayVersion => { diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index f6e555055..80c1af0e3 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -12,6 +12,7 @@ use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; use uucore::translate; +use uucore::LocalizedCommand; use uucore::format_usage; use linebreak::break_lines; @@ -334,7 +335,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } - let matches = uu_app().try_get_matches_from(&args)?; + let matches = uu_app().try_get_matches_from_localized(&args); let files = extract_files(&matches)?; diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 318e3875b..c3e743d85 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -9,6 +9,7 @@ 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; @@ -31,7 +32,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().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let bytes = matches.get_flag(options::BYTES); let spaces = matches.get_flag(options::SPACES); diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index 498c72802..9d6947223 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -14,6 +14,7 @@ use uucore::{ }; use clap::{Arg, ArgAction, Command}; +use uucore::LocalizedCommand; use uucore::translate; mod options { @@ -47,7 +48,7 @@ fn infallible_gid2grp(gid: &u32) -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let users: Vec = matches .get_many::(options::USERS) diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index a6fc13e23..4204b979e 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -15,6 +15,7 @@ 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; @@ -181,7 +182,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.try_get_matches_from(args)?; + let matches = command.try_get_matches_from_localized(args); let input_length: Option<&usize> = if binary_name == "b2sum" { matches.get_one::(options::LENGTH) diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index b7e4334c4..bfd8a076a 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -14,6 +14,7 @@ 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; @@ -549,7 +550,8 @@ fn uu_head(options: &HeadOptions) -> UResult<()> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(arg_iterate(args)?)?; + let args_vec: Vec<_> = arg_iterate(args)?.collect(); + let matches = uu_app().try_get_matches_from_localized(args_vec); let args = match HeadOptions::get_from(&matches) { Ok(o) => o, Err(s) => { diff --git a/src/uu/hostid/src/hostid.rs b/src/uu/hostid/src/hostid.rs index f5054389b..c29b57489 100644 --- a/src/uu/hostid/src/hostid.rs +++ b/src/uu/hostid/src/hostid.rs @@ -9,11 +9,12 @@ 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().try_get_matches_from(args)?; + uu_app().try_get_matches_from_localized(args); hostid(); Ok(()) } diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index 558c6aff1..74f2c48d9 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -12,6 +12,7 @@ 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; @@ -60,7 +61,7 @@ mod wsa { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); #[cfg(windows)] let _handle = wsa::start().map_err_context(|| translate!("hostname-error-winsock"))?; diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 41e926450..688ac232a 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -44,6 +44,7 @@ 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}; @@ -121,7 +122,7 @@ struct State { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app() .after_help(translate!("id-after-help")) - .try_get_matches_from(args)?; + .try_get_matches_from_localized(args); let users: Vec = matches .get_many::(options::ARG_USERS) diff --git a/src/uu/install/Cargo.toml b/src/uu/install/Cargo.toml index 4f434485e..dc249b5d0 100644 --- a/src/uu/install/Cargo.toml +++ b/src/uu/install/Cargo.toml @@ -22,7 +22,7 @@ clap = { workspace = true } filetime = { workspace = true } file_diff = { workspace = true } thiserror = { workspace = true } -uucore = { workspace = true, features = [ +uucore = { workspace = true, default-features = true, features = [ "backup-control", "buf-copy", "fs", diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index ac1948c51..338f90f6c 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -16,6 +16,7 @@ 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; @@ -165,7 +166,7 @@ static ARG_FILES: &str = "files"; /// #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let paths: Vec = matches .get_many::(ARG_FILES) diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index 3dec9bef1..6ba16d101 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -16,6 +16,7 @@ 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; @@ -821,7 +822,7 @@ fn parse_settings(matches: &clap::ArgMatches) -> UResult { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let settings = parse_settings(&matches)?; diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 148489b2d..b1dc4dc92 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -13,6 +13,7 @@ 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}; @@ -40,7 +41,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().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let mode = if matches.get_flag(options::TABLE) { Mode::Table diff --git a/src/uu/link/src/link.rs b/src/uu/link/src/link.rs index 20528a700..327ef09b0 100644 --- a/src/uu/link/src/link.rs +++ b/src/uu/link/src/link.rs @@ -8,6 +8,7 @@ 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; @@ -19,7 +20,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let files: Vec<_> = matches .get_many::(options::FILES) .unwrap_or_default() diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index df53b16b8..5d5ce9bdc 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -23,6 +23,7 @@ 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}; @@ -94,7 +95,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { backup_control::BACKUP_CONTROL_LONG_HELP ); - let matches = uu_app().after_help(after_help).try_get_matches_from(args)?; + let matches = uu_app() + .after_help(after_help) + .try_get_matches_from_localized(args); /* the list of files */ diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 77d8fe15c..d34712339 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -7,6 +7,7 @@ use clap::Command; use std::ffi::CStr; +use uucore::LocalizedCommand; use uucore::translate; use uucore::{error::UResult, show_error}; @@ -23,7 +24,7 @@ fn get_userlogin() -> Option { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let _ = uu_app().try_get_matches_from(args)?; + let _ = uu_app().try_get_matches_from_localized(args); match get_userlogin() { Some(userlogin) => println!("{userlogin}"), diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index f4c685863..5e9477c29 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1103,9 +1103,7 @@ impl Config { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let command = uu_app(); - - let matches = match command.try_get_matches_from(args) { + let matches = match uu_app().try_get_matches_from(args) { // clap successfully parsed the arguments: Ok(matches) => matches, // --help, --version, etc.: @@ -1118,7 +1116,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // All other argument parsing errors cause exit code 2: Err(e) => { - return Err(USimpleError::new(2, e.to_string())); + uucore::clap_localization::handle_clap_error_with_exit_code(e, "ls", 2); } }; diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index b2c349337..d1cf51647 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -15,6 +15,7 @@ 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}; @@ -81,7 +82,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // " of each created directory to CTX"), let matches = uu_app() .after_help(translate!("mkdir-after-help")) - .try_get_matches_from(args)?; + .try_get_matches_from_localized(args); let dirs = matches .get_many::(options::DIRS) diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 33d842d92..8032a5fad 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -12,6 +12,7 @@ use uucore::display::Quotable; use uucore::error::{UResult, USimpleError}; use uucore::translate; +use uucore::LocalizedCommand; use uucore::{format_usage, show}; mod options { @@ -23,7 +24,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let mode = calculate_mode(matches.get_one::(options::MODE)) .map_err(|e| USimpleError::new(1, translate!("mkfifo-error-invalid-mode", "error" => e)))?; diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 5bd79ade9..53b7eb8d2 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -10,6 +10,7 @@ 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; @@ -111,7 +112,7 @@ fn mknod(file_name: &str, config: Config) -> i32 { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let file_type = matches.get_one::("type").unwrap(); diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 90ac7c875..b1dbacf71 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -333,6 +333,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = match uu_app().try_get_matches_from(&args) { Ok(m) => m, 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); + } if e.kind() == clap::error::ErrorKind::TooManyValues && e.context().any(|(kind, val)| { kind == clap::error::ContextKind::InvalidArg diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index 4bd2e80df..829e4f53b 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -26,6 +26,7 @@ use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::format_usage; use uucore::{display::Quotable, show}; +use uucore::LocalizedCommand; use uucore::translate; #[derive(Debug)] @@ -151,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { print!("\r"); println!("{panic_info}"); })); - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let mut options = Options::from(&matches); if let Some(files) = matches.get_many::(options::FILES) { let length = files.len(); diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 948e486c9..0fd44643e 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -10,7 +10,8 @@ mod error; mod hardlink; use clap::builder::ValueParser; -use clap::{Arg, ArgAction, ArgMatches, Command, error::ErrorKind}; +use clap::error::ErrorKind; +use clap::{Arg, ArgAction, ArgMatches, Command}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; #[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))] @@ -51,6 +52,7 @@ 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}; @@ -151,8 +153,7 @@ static OPT_SELINUX: &str = "selinux"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let mut app = uu_app(); - let matches = app.try_get_matches_from_mut(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let files: Vec = matches .get_many::(ARG_FILES) @@ -161,11 +162,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .collect(); if files.len() == 1 && !matches.contains_id(OPT_TARGET_DIRECTORY) { - app.error( - ErrorKind::TooFewValues, - translate!("mv-error-insufficient-arguments", "arg_files" => ARG_FILES), - ) - .exit(); + return Err(UUsageError::new( + 1, + format!( + "The argument '<{ARG_FILES}>...' requires at least 2 values, but only 1 was provided" + ), + )); } let overwrite_mode = determine_overwrite_mode(&matches); diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 1e5eb3d72..414f5d735 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -10,6 +10,7 @@ use std::path::Path; use uucore::error::{FromIo, UResult, USimpleError, set_exit_code}; use uucore::translate; +use uucore::LocalizedCommand; use uucore::{format_usage, show_error}; mod helper; @@ -176,7 +177,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let mut settings = Settings::default(); diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index f7be033bd..9d913d33e 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -7,6 +7,7 @@ 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; @@ -26,7 +27,7 @@ static OPT_IGNORE: &str = "ignore"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let ignore = match matches.get_one::(OPT_IGNORE) { Some(numstr) => match numstr.trim().parse::() { diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index f8dddd8c6..852016495 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -13,6 +13,7 @@ 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; @@ -254,7 +255,7 @@ fn parse_options(args: &ArgMatches) -> Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?; diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 7db53b6b6..3562e38c3 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -46,6 +46,7 @@ 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}; @@ -220,7 +221,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let clap_opts = uu_app(); - let clap_matches = clap_opts.try_get_matches_from(&args)?; + let clap_matches = clap_opts.try_get_matches_from_localized(&args); let od_options = OdOptions::new(&clap_matches, &args)?; diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index b6b9b59a8..6dc3d79e9 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -10,6 +10,7 @@ use std::io::{BufRead, BufReader, Stdin, Write, stdin, stdout}; use std::iter::Cycle; 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; @@ -24,7 +25,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let serial = matches.get_flag(options::SERIAL); let delimiters = matches.get_one::(options::DELIMITER).unwrap(); diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 3b7a3c164..d5a318f0d 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -8,6 +8,7 @@ use clap::{Arg, ArgAction, Command}; 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; @@ -34,7 +35,7 @@ const POSIX_NAME_MAX: usize = 14; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); // set working mode let is_posix = matches.get_flag(options::POSIX); diff --git a/src/uu/pinky/src/platform/openbsd.rs b/src/uu/pinky/src/platform/openbsd.rs index fb7cd155b..c53839c47 100644 --- a/src/uu/pinky/src/platform/openbsd.rs +++ b/src/uu/pinky/src/platform/openbsd.rs @@ -5,11 +5,12 @@ // 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().try_get_matches_from(args)?; + let _matches = uu_app().try_get_matches_from_localized(args); println!("{}", translate!("pinky-unsupported-openbsd")); Ok(()) } diff --git a/src/uu/pinky/src/platform/unix.rs b/src/uu/pinky/src/platform/unix.rs index 59c226046..e80f02d05 100644 --- a/src/uu/pinky/src/platform/unix.rs +++ b/src/uu/pinky/src/platform/unix.rs @@ -9,6 +9,7 @@ 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; @@ -34,7 +35,7 @@ fn get_long_usage() -> String { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app() .after_help(get_long_usage()) - .try_get_matches_from(args)?; + .try_get_matches_from_localized(args); let users: Vec = matches .get_many::(options::USER) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index fbad8c93a..3e7bcd3d9 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -16,6 +16,7 @@ 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; @@ -315,8 +316,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let opt_args = recreate_arguments(&args); - let mut command = uu_app(); - let matches = command.try_get_matches_from_mut(opt_args)?; + let command = uu_app(); + let matches = command.try_get_matches_from_mut_localized(opt_args); let mut files = matches .get_many::(options::FILES) diff --git a/src/uu/printenv/src/printenv.rs b/src/uu/printenv/src/printenv.rs index 063be33ff..6d875c537 100644 --- a/src/uu/printenv/src/printenv.rs +++ b/src/uu/printenv/src/printenv.rs @@ -5,6 +5,7 @@ use clap::{Arg, ArgAction, Command}; use std::env; +use uucore::LocalizedCommand; use uucore::translate; use uucore::{error::UResult, format_usage}; @@ -14,7 +15,7 @@ static ARG_VARIABLES: &str = "variables"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from_localized(args); let variables: Vec = matches .get_many::(ARG_VARIABLES) diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index 2c536bcb6..08408b40b 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -6,6 +6,7 @@ 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; @@ -21,7 +22,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from_localized(args); let format = matches .get_one::(options::FORMAT) diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 78ec37a47..f2a26ae82 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -15,6 +15,7 @@ use std::num::ParseIntError; 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; @@ -728,7 +729,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let config = get_config(&matches)?; let input_files; diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index 39dad5f9e..5fe5ae0ae 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -13,6 +13,7 @@ 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"; @@ -109,7 +110,7 @@ fn logical_path() -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(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 diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index 8f61d9ab2..c9f06ff5b 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -9,6 +9,7 @@ use clap::{Arg, ArgAction, Command}; use std::fs; use std::io::{Write, stdout}; use std::path::{Path, PathBuf}; +use uucore::LocalizedCommand; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::fs::{MissingHandling, ResolveMode, canonicalize}; @@ -29,7 +30,7 @@ const ARG_FILES: &str = "files"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let mut no_trailing_delimiter = matches.get_flag(OPT_NO_NEWLINE); let use_zero = matches.get_flag(OPT_ZERO); diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index f7971aa80..9595e25f6 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -23,6 +23,7 @@ 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)] @@ -143,7 +144,7 @@ static ARG_FILES: &str = "files"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let files: Vec<_> = matches .get_many::(ARG_FILES) diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index 34346c0d6..bbbcae744 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -15,6 +15,7 @@ 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"; @@ -25,7 +26,7 @@ static ARG_DIRS: &str = "dirs"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let opts = Opts { ignore: matches.get_flag(OPT_IGNORE_FAIL_NON_EMPTY), diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index a34797835..73f4c067c 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -14,6 +14,7 @@ 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; @@ -238,7 +239,7 @@ impl<'a> BytesWriter<'a> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); if !matches.contains_id(options::FILE) { return Err(UUsageError::new( diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 254875eaa..d2e854b9b 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -17,6 +17,7 @@ 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; @@ -51,7 +52,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let mode = if matches.get_flag(options::ECHO) { Mode::Echo( diff --git a/src/uu/sleep/src/sleep.rs b/src/uu/sleep/src/sleep.rs index 1731c2af1..37d54ee99 100644 --- a/src/uu/sleep/src/sleep.rs +++ b/src/uu/sleep/src/sleep.rs @@ -6,6 +6,7 @@ use clap::{Arg, ArgAction, Command}; use std::thread; use std::time::Duration; +use uucore::LocalizedCommand; use uucore::translate; use uucore::{ error::{UResult, USimpleError, UUsageError}, @@ -20,7 +21,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let numbers = matches .get_many::(options::NUMBER) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 74b6253fb..29346315b 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1050,6 +1050,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // 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; + if e.kind() == clap::error::ErrorKind::UnknownArgument { + handle_clap_error_with_exit_code(e, uucore::util_name(), 2); + } e.print().unwrap(); if e.use_stderr() { set_exit_code(2); diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index b8351c31e..a2c85464f 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -26,6 +26,7 @@ use uucore::translate; use uucore::parser::parse_size::parse_size_u64; +use uucore::LocalizedCommand; use uucore::format_usage; use uucore::uio_error; @@ -51,7 +52,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().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); match Settings::from(&matches, obs_lines.as_deref()) { Ok(settings) => split(&settings), diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 6bc0aa0b3..f39e24842 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -27,6 +27,7 @@ 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)] @@ -1220,7 +1221,7 @@ impl Stater { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app() .after_help(translate!("stat-after-help")) - .try_get_matches_from(args)?; + .try_get_matches_from_localized(args); let stater = Stater::new(&matches)?; let exit_status = stater.exec(); diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 5de8f9e36..63b0a6e62 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -29,6 +29,7 @@ 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; @@ -242,7 +243,7 @@ ioctl_write_ptr_bad!( #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let opts = Options::from(&matches)?; diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 8359ec002..061fc2509 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -13,6 +13,7 @@ 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)> { @@ -98,7 +99,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let files: Vec = match matches.get_many::(options::FILE) { Some(v) => v.cloned().collect(), diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 95af36c80..9e643aa7c 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -13,6 +13,7 @@ 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; @@ -173,7 +174,7 @@ mod platform { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let files: Vec = matches .get_many::(ARG_FILES) .map(|v| v.map(ToString::to_string).collect()) diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 52d885bf4..4911a4b09 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -21,6 +21,7 @@ use uucore::{format_usage, show}; use crate::error::TacError; +use uucore::LocalizedCommand; use uucore::translate; mod options { @@ -32,7 +33,7 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let before = matches.get_flag(options::BEFORE); let regex = matches.get_flag(options::REGEX); diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index d7d4b6704..14c015bf7 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -17,6 +17,7 @@ use uucore::{format_usage, show_error}; // spell-checker:ignore nopipe +use uucore::LocalizedCommand; #[cfg(unix)] use uucore::signals::{enable_pipe_errors, ignore_interrupts}; @@ -51,7 +52,7 @@ enum OutputErrorMode { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let append = matches.get_flag(options::APPEND); let ignore_interrupts = matches.get_flag(options::IGNORE_INTERRUPTS); diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index fde4cdc1b..1f413e4e0 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -20,6 +20,7 @@ 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; @@ -186,7 +187,7 @@ fn shr2(s: &str) -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let mut filenames: Vec<&String> = matches .get_many::(ARG_FILES) diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 5e5316dbc..fbcde13d4 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -13,6 +13,7 @@ use operation::{ }; use std::ffi::OsString; use std::io::{Write, stdin, stdout}; +use uucore::LocalizedCommand; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::fs::is_stdin_directory; @@ -40,7 +41,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { libc::signal(libc::SIGPIPE, libc::SIG_DFL); } - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let delete_flag = matches.get_flag(options::DELETE); let complement_flag = matches.get_flag(options::COMPLEMENT); diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 646303bab..dab1ffc9c 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -11,6 +11,7 @@ use uucore::display::Quotable; use uucore::error::{UError, UResult}; use uucore::{format_usage, show}; +use uucore::LocalizedCommand; use uucore::translate; mod options { @@ -43,7 +44,7 @@ impl UError for TsortError {} #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let input = matches .get_one::(options::FILE) diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index d5c843fcd..b893fa8b4 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -18,7 +18,10 @@ mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + 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 silent = matches.get_flag(options::SILENT); diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index 092ec1a64..c30c00bb4 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -7,6 +7,7 @@ use clap::{Arg, ArgAction, Command}; use platform_info::*; +use uucore::LocalizedCommand; use uucore::translate; use uucore::{ error::{UResult, USimpleError}, @@ -120,7 +121,7 @@ pub struct Options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let options = Options { all: matches.get_flag(options::ALL), diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index 47d6e04d0..c5935b40e 100644 --- a/src/uu/unlink/src/unlink.rs +++ b/src/uu/unlink/src/unlink.rs @@ -9,6 +9,7 @@ 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; @@ -18,7 +19,7 @@ static OPT_PATH: &str = "FILE"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let path: &Path = matches.get_one::(OPT_PATH).unwrap().as_ref(); diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index 41d0f6464..d8470e196 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -17,6 +17,7 @@ use uucore::uptime::*; use clap::{Arg, ArgAction, Command, ValueHint, builder::ValueParser}; +use uucore::LocalizedCommand; use uucore::format_usage; #[cfg(unix)] @@ -47,7 +48,7 @@ impl UError for UptimeError { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); #[cfg(unix)] let file_path = matches.get_one::(options::PATH); diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index 67761ca06..92c50d7cc 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -16,6 +16,7 @@ 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}; @@ -37,7 +38,7 @@ fn get_long_usage() -> String { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app() .after_help(get_long_usage()) - .try_get_matches_from(args)?; + .try_get_matches_from_localized(args); let maybe_file: Option<&Path> = matches.get_one::(ARG_FILE).map(AsRef::as_ref); diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 920f4602f..140001c9e 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -26,6 +26,7 @@ use unicode_width::UnicodeWidthChar; use utf8::{BufReadDecoder, BufReadDecoderError}; use uucore::translate; +use uucore::LocalizedCommand; use uucore::{ error::{FromIo, UError, UResult}, format_usage, @@ -376,7 +377,7 @@ impl UError for WcError { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let settings = Settings::new(&matches); let inputs = Inputs::new(&matches)?; diff --git a/src/uu/who/src/platform/openbsd.rs b/src/uu/who/src/platform/openbsd.rs index 8e0bbd3b9..8d1e31dab 100644 --- a/src/uu/who/src/platform/openbsd.rs +++ b/src/uu/who/src/platform/openbsd.rs @@ -7,11 +7,12 @@ 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().try_get_matches_from(args)?; + let _matches = uu_app().try_get_matches_from_localized(args); println!("{}", translate!("who-unsupported-openbsd")); Ok(()) } diff --git a/src/uu/who/src/platform/unix.rs b/src/uu/who/src/platform/unix.rs index f9f322a5d..70b46a593 100644 --- a/src/uu/who/src/platform/unix.rs +++ b/src/uu/who/src/platform/unix.rs @@ -13,6 +13,7 @@ use uucore::error::{FromIo, UResult}; use uucore::libc::{S_IWGRP, STDIN_FILENO, ttyname}; use uucore::translate; +use uucore::LocalizedCommand; use uucore::utmpx::{self, Utmpx, time}; use std::borrow::Cow; @@ -28,7 +29,7 @@ fn get_long_usage() -> String { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app() .after_help(get_long_usage()) - .try_get_matches_from(args)?; + .try_get_matches_from_localized(args); let files: Vec = matches .get_many::(options::FILE) diff --git a/src/uu/whoami/src/whoami.rs b/src/uu/whoami/src/whoami.rs index 928e81edf..3b0b11ead 100644 --- a/src/uu/whoami/src/whoami.rs +++ b/src/uu/whoami/src/whoami.rs @@ -5,6 +5,7 @@ use clap::Command; use std::ffi::OsString; +use uucore::LocalizedCommand; use uucore::display::println_verbatim; use uucore::error::{FromIo, UResult}; use uucore::translate; @@ -13,7 +14,7 @@ mod platform; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - uu_app().try_get_matches_from(args)?; + uu_app().try_get_matches_from_localized(args); let username = whoami()?; println_verbatim(username).map_err_context(|| translate!("whoami-error-failed-to-print"))?; Ok(()) diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index 6b2bc6495..ec818a955 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -9,6 +9,7 @@ use clap::{Arg, ArgAction, Command, builder::ValueParser}; use std::error::Error; use std::ffi::OsString; use std::io::{self, Write}; +use uucore::LocalizedCommand; use uucore::error::{UResult, USimpleError}; use uucore::format_usage; #[cfg(unix)] @@ -21,7 +22,7 @@ const BUF_SIZE: usize = 16 * 1024; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().try_get_matches_from(args)?; + let matches = uu_app().try_get_matches_from_localized(args); let mut buffer = Vec::with_capacity(BUF_SIZE); args_into_buffer(&mut buffer, matches.get_many::("STRING")).unwrap();