Skip to content

Commit 303a211

Browse files
authored
Merge pull request #8542 from sylvestre/clap-loca-improv-2
clap/locale: fix the colors for all programs (Closes: #8501)
2 parents 0ec247f + 23f3551 commit 303a211

File tree

121 files changed

+2426
-1801
lines changed

Some content is hidden

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

121 files changed

+2426
-1801
lines changed

.vscode/cSpell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"**/*.svg",
3030
"src/uu/*/locales/*.ftl",
3131
"src/uucore/locales/*.ftl",
32-
".devcontainer/**"
32+
".devcontainer/**",
33+
"util/gnu-patches/**",
3334
],
3435

3536
"enableGlobDot": true,

.vscode/cspell.dictionaries/workspace.wordlist.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,12 @@ getcwd
349349
# * other
350350
weblate
351351
algs
352+
353+
# translation tests
354+
CLICOLOR
355+
erreur
356+
Utilisation
357+
merror
358+
merreur
359+
verbo
360+
inattendu

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ chrono = { version = "0.4.41", default-features = false, features = [
301301
"alloc",
302302
"clock",
303303
] }
304-
clap = { version = "4.5", features = ["wrap_help", "cargo"] }
304+
clap = { version = "4.5", features = ["wrap_help", "cargo", "color"] }
305305
clap_complete = "4.4"
306306
clap_mangen = "0.2"
307307
compare = "0.1.0"

src/uu/arch/src/arch.rs

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

88
use clap::Command;
9-
use uucore::LocalizedCommand;
109
use uucore::error::{UResult, USimpleError};
1110
use uucore::translate;
1211

1312
#[uucore::main]
1413
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
15-
uu_app().get_matches_from_localized(args);
14+
uucore::clap_localization::handle_clap_result(uu_app(), args)?;
1615

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

src/uu/base32/src/base_common.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::ffi::OsString;
1010
use std::fs::File;
1111
use std::io::{self, ErrorKind, Read, Seek, SeekFrom};
1212
use std::path::{Path, PathBuf};
13-
use uucore::LocalizedCommand;
1413
use uucore::display::Quotable;
1514
use uucore::encoding::{
1615
BASE2LSBF, BASE2MSBF, EncodingWrapper, Format, SupportsFastDecodeAndEncode, Z85Wrapper,
@@ -101,17 +100,17 @@ pub fn parse_base_cmd_args(
101100
usage: &str,
102101
) -> UResult<Config> {
103102
let command = base_app(about, usage);
104-
let matches = command.get_matches_from_localized(args);
103+
let matches = uucore::clap_localization::handle_clap_result(command, args)?;
105104
Config::from(&matches)
106105
}
107106

108107
pub fn base_app(about: &'static str, usage: &str) -> Command {
109-
Command::new(uucore::util_name())
108+
let cmd = Command::new(uucore::util_name())
110109
.version(uucore::crate_version!())
111-
.help_template(uucore::localized_help_template(uucore::util_name()))
112110
.about(about)
113111
.override_usage(format_usage(usage))
114-
.infer_long_args(true)
112+
.infer_long_args(true);
113+
uucore::clap_localization::configure_localized_command(cmd)
115114
// Format arguments.
116115
.arg(
117116
Arg::new(options::DECODE)

src/uu/basename/src/basename.rs

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

18-
use uucore::LocalizedCommand;
1918
use uucore::translate;
2019

2120
pub mod options {
@@ -30,7 +29,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
3029
//
3130
// Argument parsing
3231
//
33-
let matches = uu_app().get_matches_from_localized(args);
32+
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
3433

3534
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));
3635

src/uu/basenc/src/basenc.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use clap::{Arg, ArgAction, Command};
99
use uu_base32::base_common::{self, BASE_CMD_PARSE_ERROR, Config};
10-
use uucore::error::UClapError;
1110
use uucore::translate;
1211
use uucore::{
1312
encoding::Format,
@@ -64,9 +63,7 @@ pub fn uu_app() -> Command {
6463
}
6564

6665
fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> {
67-
let matches = uu_app()
68-
.try_get_matches_from(args.collect_lossy())
69-
.with_exit_code(1)?;
66+
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args.collect_lossy())?;
7067

7168
let encodings = get_encodings();
7269
let format = encodings

src/uu/cat/src/cat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::os::unix::fs::FileTypeExt;
2323
#[cfg(unix)]
2424
use std::os::unix::net::UnixStream;
2525
use thiserror::Error;
26-
use uucore::LocalizedCommand;
2726
use uucore::display::Quotable;
2827
use uucore::error::UResult;
2928
#[cfg(not(target_os = "windows"))]
@@ -232,7 +231,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
232231
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
233232
}
234233

235-
let matches = uu_app().get_matches_from_localized(args);
234+
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
236235

237236
let number_mode = if matches.get_flag(options::NUMBER_NONBLANK) {
238237
NumberingMode::NonEmpty

src/uu/chcon/src/chcon.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
#![allow(clippy::upper_case_acronyms)]
88

99
use clap::builder::ValueParser;
10-
use uucore::LocalizedCommand;
1110
use uucore::error::{UResult, USimpleError, UUsageError};
1211
use uucore::translate;
1312
use uucore::{display::Quotable, format_usage, show_error, show_warning};
1413

15-
use clap::{Arg, ArgAction, Command};
14+
use clap::{Arg, ArgAction, ArgMatches, Command};
1615
use selinux::{OpaqueSecurityContext, SecurityContext};
1716

1817
use std::borrow::Cow;
@@ -58,9 +57,9 @@ pub mod options {
5857

5958
#[uucore::main]
6059
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
61-
let config = uu_app();
60+
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
6261

63-
let options = match parse_command_line(config, args) {
62+
let options = match parse_command_line(&matches) {
6463
Ok(r) => r,
6564
Err(r) => {
6665
if let Error::CommandLine(r) = r {
@@ -155,20 +154,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
155154
}
156155

157156
pub fn uu_app() -> Command {
158-
Command::new(uucore::util_name())
157+
let cmd = Command::new(uucore::util_name())
159158
.version(uucore::crate_version!())
160-
.help_template(uucore::localized_help_template(uucore::util_name()))
161159
.about(translate!("chcon-about"))
162160
.override_usage(format_usage(&translate!("chcon-usage")))
163-
.infer_long_args(true)
164-
.disable_help_flag(true)
161+
.infer_long_args(true);
162+
uucore::clap_localization::configure_localized_command(cmd)
165163
.args_override_self(true)
166-
.arg(
167-
Arg::new(options::HELP)
168-
.long(options::HELP)
169-
.help(translate!("chcon-help-help"))
170-
.action(ArgAction::Help),
171-
)
164+
.disable_help_flag(true)
172165
.arg(
173166
Arg::new(options::dereference::DEREFERENCE)
174167
.long(options::dereference::DEREFERENCE)
@@ -183,6 +176,12 @@ pub fn uu_app() -> Command {
183176
.help(translate!("chcon-help-no-dereference"))
184177
.action(ArgAction::SetTrue),
185178
)
179+
.arg(
180+
Arg::new("help")
181+
.long("help")
182+
.help(translate!("help"))
183+
.action(ArgAction::Help),
184+
)
186185
.arg(
187186
Arg::new(options::preserve_root::PRESERVE_ROOT)
188187
.long(options::preserve_root::PRESERVE_ROOT)
@@ -304,9 +303,7 @@ struct Options {
304303
files: Vec<PathBuf>,
305304
}
306305

307-
fn parse_command_line(config: Command, args: impl uucore::Args) -> Result<Options> {
308-
let matches = config.get_matches_from_localized(args);
309-
306+
fn parse_command_line(matches: &ArgMatches) -> Result<Options> {
310307
let verbose = matches.get_flag(options::VERBOSE);
311308

312309
let (recursive_mode, affect_symlink_referent) = if matches.get_flag(options::RECURSIVE) {

src/uu/chgrp/src/chgrp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
9898
}
9999

100100
pub fn uu_app() -> Command {
101-
Command::new(uucore::util_name())
101+
let cmd = Command::new(uucore::util_name())
102102
.version(uucore::crate_version!())
103-
.help_template(uucore::localized_help_template(uucore::util_name()))
104103
.about(translate!("chgrp-about"))
105104
.override_usage(format_usage(&translate!("chgrp-usage")))
106-
.infer_long_args(true)
105+
.infer_long_args(true);
106+
uucore::clap_localization::configure_localized_command(cmd)
107107
.disable_help_flag(true)
108108
.arg(
109109
Arg::new(options::HELP)

0 commit comments

Comments
 (0)