Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a570c3

Browse files
committed
l10n: Migrate all utilities to use LocalizedCommand
1 parent 206da5c commit 4a570c3

File tree

83 files changed

+193
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+193
-104
lines changed

src/bin/coreutils.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,18 @@ fn find_prefixed_util<'a>(
8181
}
8282

8383
fn setup_localization_or_exit(util_name: &str) {
84-
locale::setup_localization(get_canonical_util_name(util_name)).unwrap_or_else(|err| {
85-
match err {
86-
uucore::locale::LocalizationError::ParseResource {
87-
error: err_msg,
88-
snippet,
89-
} => eprintln!("Localization parse error at {snippet}: {err_msg}"),
90-
other => eprintln!("Could not init the localization system: {other}"),
91-
}
92-
process::exit(99)
93-
});
84+
locale::setup_localization_with_common(get_canonical_util_name(util_name)).unwrap_or_else(
85+
|err| {
86+
match err {
87+
uucore::locale::LocalizationError::ParseResource {
88+
error: err_msg,
89+
snippet,
90+
} => eprintln!("Localization parse error at {snippet}: {err_msg}"),
91+
other => eprintln!("Could not init the localization system: {other}"),
92+
}
93+
process::exit(99)
94+
},
95+
);
9496
}
9597

9698
#[allow(clippy::cognitive_complexity)]

src/uu/arch/src/arch.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
use platform_info::*;
77

88
use clap::Command;
9+
use uucore::LocalizedCommand;
910
use uucore::error::{UResult, USimpleError};
1011
use uucore::translate;
1112

1213
#[uucore::main]
1314
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
14-
uu_app().try_get_matches_from(args)?;
15+
uu_app().try_get_matches_from_localized(args);
1516

1617
let uts =
1718
PlatformInfo::new().map_err(|_e| USimpleError::new(1, translate!("cannot-get-system")))?;

src/uu/base32/src/base_common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ use clap::{Arg, ArgAction, Command};
99
use std::fs::File;
1010
use std::io::{self, ErrorKind, Read, Seek, SeekFrom};
1111
use std::path::{Path, PathBuf};
12+
use uucore::LocalizedCommand;
1213
use uucore::display::Quotable;
1314
use uucore::encoding::{
14-
BASE2LSBF, BASE2MSBF, Format, Z85Wrapper,
15+
BASE2LSBF, BASE2MSBF, EncodingWrapper, Format, SupportsFastDecodeAndEncode, Z85Wrapper,
1516
for_base_common::{BASE32, BASE32HEX, BASE64, BASE64_NOPAD, BASE64URL, HEXUPPER_PERMISSIVE},
1617
};
17-
use uucore::encoding::{EncodingWrapper, SupportsFastDecodeAndEncode};
1818
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
1919
use uucore::format_usage;
2020
use uucore::translate;
21-
2221
pub const BASE_CMD_PARSE_ERROR: i32 = 1;
2322

2423
/// 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(
10099
usage: &str,
101100
) -> UResult<Config> {
102101
let command = base_app(about, usage);
103-
Config::from(&command.try_get_matches_from(args)?)
102+
let matches = command.try_get_matches_from_localized(args);
103+
Config::from(&matches)
104104
}
105105

106106
pub fn base_app(about: &'static str, usage: &str) -> Command {

src/uu/basename/src/basename.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use uucore::error::{UResult, UUsageError};
1515
use uucore::format_usage;
1616
use uucore::line_ending::LineEnding;
1717

18+
use uucore::LocalizedCommand;
1819
use uucore::translate;
1920

2021
pub mod options {
@@ -29,7 +30,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
2930
//
3031
// Argument parsing
3132
//
32-
let matches = uu_app().try_get_matches_from(args)?;
33+
let matches = uu_app().try_get_matches_from_localized(args);
3334

3435
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));
3536

src/uu/basenc/src/basenc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use uucore::{
1313
encoding::Format,
1414
error::{UResult, UUsageError},
1515
};
16-
1716
fn get_encodings() -> Vec<(&'static str, Format, String)> {
1817
vec![
1918
("base64", Format::Base64, translate!("basenc-help-base64")),

src/uu/cat/src/cat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::os::unix::fs::FileTypeExt;
2222
#[cfg(unix)]
2323
use std::os::unix::net::UnixStream;
2424
use thiserror::Error;
25+
use uucore::LocalizedCommand;
2526
use uucore::display::Quotable;
2627
use uucore::error::UResult;
2728
#[cfg(not(target_os = "windows"))]
@@ -230,7 +231,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
230231
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
231232
}
232233

233-
let matches = uu_app().try_get_matches_from(args)?;
234+
let matches = uu_app().try_get_matches_from_localized(args);
234235

235236
let number_mode = if matches.get_flag(options::NUMBER_NONBLANK) {
236237
NumberingMode::NonEmpty

src/uu/chcon/src/chcon.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![allow(clippy::upper_case_acronyms)]
88

99
use clap::builder::ValueParser;
10+
use uucore::LocalizedCommand;
1011
use uucore::error::{UResult, USimpleError, UUsageError};
1112
use uucore::translate;
1213
use uucore::{display::Quotable, format_usage, show_error, show_warning};
@@ -303,7 +304,7 @@ struct Options {
303304
}
304305

305306
fn parse_command_line(config: Command, args: impl uucore::Args) -> Result<Options> {
306-
let matches = config.try_get_matches_from(args)?;
307+
let matches = config.try_get_matches_from_localized(args);
307308

308309
let verbose = matches.get_flag(options::VERBOSE);
309310

src/uu/chmod/src/chmod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::fs;
1111
use std::os::unix::fs::{MetadataExt, PermissionsExt};
1212
use std::path::Path;
1313
use thiserror::Error;
14+
use uucore::LocalizedCommand;
1415
use uucore::display::Quotable;
1516
use uucore::error::{ExitCode, UError, UResult, USimpleError, UUsageError, set_exit_code};
1617
use uucore::fs::display_permissions_unix;
@@ -112,7 +113,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
112113
let (parsed_cmode, args) = extract_negative_modes(args.skip(1)); // skip binary name
113114
let matches = uu_app()
114115
.after_help(translate!("chmod-after-help"))
115-
.try_get_matches_from(args)?;
116+
.try_get_matches_from_localized(args);
116117

117118
let changes = matches.get_flag(options::CHANGES);
118119
let quiet = matches.get_flag(options::QUIET);

src/uu/cksum/src/cksum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use uucore::checksum::{
2020
};
2121
use uucore::translate;
2222

23+
use uucore::LocalizedCommand;
2324
use uucore::{
2425
encoding,
2526
error::{FromIo, UResult, USimpleError},
@@ -236,7 +237,7 @@ fn handle_tag_text_binary_flags<S: AsRef<OsStr>>(
236237

237238
#[uucore::main]
238239
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
239-
let matches = uu_app().try_get_matches_from(args)?;
240+
let matches = uu_app().try_get_matches_from_localized(args);
240241

241242
let check = matches.get_flag(options::CHECK);
242243

src/uu/comm/src/comm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use std::cmp::Ordering;
99
use std::fs::{File, metadata};
1010
use std::io::{self, BufRead, BufReader, Read, Stdin, stdin};
11+
use uucore::LocalizedCommand;
1112
use uucore::error::{FromIo, UResult, USimpleError};
1213
use uucore::format_usage;
1314
use uucore::fs::paths_refer_to_same_file;
@@ -280,7 +281,7 @@ fn open_file(name: &str, line_ending: LineEnding) -> io::Result<LineReader> {
280281

281282
#[uucore::main]
282283
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
283-
let matches = uu_app().try_get_matches_from(args)?;
284+
let matches = uu_app().try_get_matches_from_localized(args);
284285
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED));
285286
let filename1 = matches.get_one::<String>(options::FILE_1).unwrap();
286287
let filename2 = matches.get_one::<String>(options::FILE_2).unwrap();

0 commit comments

Comments
 (0)