l10n: Migrate all utilities to use LocalizedCommand

This commit is contained in:
Sylvestre Ledru 2025-08-04 18:27:45 +02:00
parent e455f770f9
commit b06b1e4ea8
82 changed files with 193 additions and 101 deletions

View file

@ -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)]

View file

@ -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")))?;

View file

@ -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<Config> {
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 {

View file

@ -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));

View file

@ -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

View file

@ -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<Options> {
let matches = config.try_get_matches_from(args)?;
let matches = config.try_get_matches_from_localized(args);
let verbose = matches.get_flag(options::VERBOSE);

View file

@ -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);

View file

@ -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<S: AsRef<OsStr>>(
#[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);

View file

@ -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<LineReader> {
#[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::<String>(options::FILE_1).unwrap();
let filename2 = matches.get_one::<String>(options::FILE_2).unwrap();

View file

@ -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)?;

View file

@ -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::<String>(options::FILE).unwrap();

View file

@ -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);

View file

@ -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::<String>(OPT_FORMAT) {
if !form.starts_with('+') {

View file

@ -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

View file

@ -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)]
{

View file

@ -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::<String>(options::FILE)

View file

@ -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));

View file

@ -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<Vec<PathBuf>, 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);

View file

@ -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);

View file

@ -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 => {

View file

@ -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)?;

View file

@ -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);

View file

@ -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<String> = matches
.get_many::<String>(options::USERS)

View file

@ -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::<usize>(options::LENGTH)

View file

@ -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) => {

View file

@ -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(())
}

View file

@ -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"))?;

View file

@ -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<String> = matches
.get_many::<String>(options::ARG_USERS)

View file

@ -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",

View file

@ -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<String> = matches
.get_many::<String>(ARG_FILES)

View file

@ -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<Settings> {
#[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)?;

View file

@ -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

View file

@ -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::<OsString>(options::FILES)
.unwrap_or_default()

View file

@ -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 */

View file

@ -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<String> {
#[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}"),

View file

@ -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);
}
};

View file

@ -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::<OsString>(options::DIRS)

View file

@ -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::<String>(options::MODE))
.map_err(|e| USimpleError::new(1, translate!("mkfifo-error-invalid-mode", "error" => e)))?;

View file

@ -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::<FileType>("type").unwrap();

View file

@ -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

View file

@ -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::<String>(options::FILES) {
let length = files.len();

View file

@ -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<OsString> = matches
.get_many::<OsString>(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);

View file

@ -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();

View file

@ -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::<String>(OPT_IGNORE) {
Some(numstr) => match numstr.trim().parse::<usize>() {

View file

@ -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<NumfmtOptions> {
#[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)?;

View file

@ -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)?;

View file

@ -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::<String>(options::DELIMITER).unwrap();

View file

@ -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);

View file

@ -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(())
}

View file

@ -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<String> = matches
.get_many::<String>(options::USER)

View file

@ -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::<String>(options::FILES)

View file

@ -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<String> = matches
.get_many::<String>(ARG_VARIABLES)

View file

@ -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::<OsString>(options::FORMAT)

View file

@ -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;

View file

@ -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<PathBuf> {
#[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

View file

@ -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);

View file

@ -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::<OsString>(ARG_FILES)

View file

@ -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),

View file

@ -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(

View file

@ -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(

View file

@ -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::<String>(options::NUMBER)

View file

@ -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);

View file

@ -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),

View file

@ -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();

View file

@ -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)?;

View file

@ -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<String> = match matches.get_many::<String>(options::FILE) {
Some(v) => v.cloned().collect(),

View file

@ -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<String> = matches
.get_many::<String>(ARG_FILES)
.map(|v| v.map(ToString::to_string).collect())

View file

@ -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);

View file

@ -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);

View file

@ -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::<String>(ARG_FILES)

View file

@ -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);

View file

@ -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::<String>(options::FILE)

View file

@ -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);

View file

@ -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),

View file

@ -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::<OsString>(OPT_PATH).unwrap().as_ref();

View file

@ -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::<OsString>(options::PATH);

View file

@ -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::<OsString>(ARG_FILE).map(AsRef::as_ref);

View file

@ -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)?;

View file

@ -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(())
}

View file

@ -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<String> = matches
.get_many::<String>(options::FILE)

View file

@ -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(())

View file

@ -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::<OsString>("STRING")).unwrap();