l10n: Migrate all utilities to use LocalizedCommand

This commit is contained in:
Sylvestre Ledru
2025-08-04 18:27:45 +02:00
parent 206da5c28b
commit 4a570c331d
83 changed files with 193 additions and 104 deletions
+12 -10
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)]
+2 -1
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")))?;
+4 -4
View File
@@ -9,16 +9,15 @@ 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;
pub const BASE_CMD_PARSE_ERROR: i32 = 1;
/// Encoded output will be formatted in lines of this length (the last line can be shorter)
@@ -100,7 +99,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 {
+2 -1
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));
-1
View File
@@ -13,7 +13,6 @@ use uucore::{
encoding::Format,
error::{UResult, UUsageError},
};
fn get_encodings() -> Vec<(&'static str, Format, String)> {
vec![
("base64", Format::Base64, translate!("basenc-help-base64")),
+2 -1
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
+2 -1
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);
+2 -1
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);
+2 -1
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);
+2 -1
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();
+2 -1
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)?;
+2 -1
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();
+2 -1
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);
+2 -1
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('+') {
+2 -1
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
+2 -1
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)]
{
+2 -1
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)
+2 -1
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));
+2 -1
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);
+2 -1
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);

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