mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Merge pull request #8542 from sylvestre/clap-loca-improv-2
clap/locale: fix the colors for all programs (Closes: #8501)
This commit is contained in:
Vendored
+2
-1
@@ -29,7 +29,8 @@
|
||||
"**/*.svg",
|
||||
"src/uu/*/locales/*.ftl",
|
||||
"src/uucore/locales/*.ftl",
|
||||
".devcontainer/**"
|
||||
".devcontainer/**",
|
||||
"util/gnu-patches/**",
|
||||
],
|
||||
|
||||
"enableGlobDot": true,
|
||||
|
||||
@@ -349,3 +349,12 @@ getcwd
|
||||
# * other
|
||||
weblate
|
||||
algs
|
||||
|
||||
# translation tests
|
||||
CLICOLOR
|
||||
erreur
|
||||
Utilisation
|
||||
merror
|
||||
merreur
|
||||
verbo
|
||||
inattendu
|
||||
|
||||
+1
-1
@@ -301,7 +301,7 @@ chrono = { version = "0.4.41", default-features = false, features = [
|
||||
"alloc",
|
||||
"clock",
|
||||
] }
|
||||
clap = { version = "4.5", features = ["wrap_help", "cargo"] }
|
||||
clap = { version = "4.5", features = ["wrap_help", "cargo", "color"] }
|
||||
clap_complete = "4.4"
|
||||
clap_mangen = "0.2"
|
||||
compare = "0.1.0"
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
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().get_matches_from_localized(args);
|
||||
uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let uts =
|
||||
PlatformInfo::new().map_err(|_e| USimpleError::new(1, translate!("cannot-get-system")))?;
|
||||
|
||||
@@ -10,7 +10,6 @@ use std::ffi::OsString;
|
||||
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, EncodingWrapper, Format, SupportsFastDecodeAndEncode, Z85Wrapper,
|
||||
@@ -101,17 +100,17 @@ pub fn parse_base_cmd_args(
|
||||
usage: &str,
|
||||
) -> UResult<Config> {
|
||||
let command = base_app(about, usage);
|
||||
let matches = command.get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(command, args)?;
|
||||
Config::from(&matches)
|
||||
}
|
||||
|
||||
pub fn base_app(about: &'static str, usage: &str) -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
let cmd = Command::new(uucore::util_name())
|
||||
.version(uucore::crate_version!())
|
||||
.help_template(uucore::localized_help_template(uucore::util_name()))
|
||||
.about(about)
|
||||
.override_usage(format_usage(usage))
|
||||
.infer_long_args(true)
|
||||
.infer_long_args(true);
|
||||
uucore::clap_localization::configure_localized_command(cmd)
|
||||
// Format arguments.
|
||||
.arg(
|
||||
Arg::new(options::DECODE)
|
||||
|
||||
@@ -15,7 +15,6 @@ use uucore::error::{UResult, UUsageError};
|
||||
use uucore::format_usage;
|
||||
use uucore::line_ending::LineEnding;
|
||||
|
||||
use uucore::LocalizedCommand;
|
||||
use uucore::translate;
|
||||
|
||||
pub mod options {
|
||||
@@ -30,7 +29,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
//
|
||||
// Argument parsing
|
||||
//
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use uu_base32::base_common::{self, BASE_CMD_PARSE_ERROR, Config};
|
||||
use uucore::error::UClapError;
|
||||
use uucore::translate;
|
||||
use uucore::{
|
||||
encoding::Format,
|
||||
@@ -64,9 +63,7 @@ pub fn uu_app() -> Command {
|
||||
}
|
||||
|
||||
fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> {
|
||||
let matches = uu_app()
|
||||
.try_get_matches_from(args.collect_lossy())
|
||||
.with_exit_code(1)?;
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args.collect_lossy())?;
|
||||
|
||||
let encodings = get_encodings();
|
||||
let format = encodings
|
||||
|
||||
@@ -23,7 +23,6 @@ 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"))]
|
||||
@@ -232,7 +231,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
|
||||
}
|
||||
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let number_mode = if matches.get_flag(options::NUMBER_NONBLANK) {
|
||||
NumberingMode::NonEmpty
|
||||
|
||||
+14
-17
@@ -7,12 +7,11 @@
|
||||
#![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};
|
||||
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||
use selinux::{OpaqueSecurityContext, SecurityContext};
|
||||
|
||||
use std::borrow::Cow;
|
||||
@@ -58,9 +57,9 @@ pub mod options {
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let config = uu_app();
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let options = match parse_command_line(config, args) {
|
||||
let options = match parse_command_line(&matches) {
|
||||
Ok(r) => r,
|
||||
Err(r) => {
|
||||
if let Error::CommandLine(r) = r {
|
||||
@@ -155,20 +154,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
let cmd = Command::new(uucore::util_name())
|
||||
.version(uucore::crate_version!())
|
||||
.help_template(uucore::localized_help_template(uucore::util_name()))
|
||||
.about(translate!("chcon-about"))
|
||||
.override_usage(format_usage(&translate!("chcon-usage")))
|
||||
.infer_long_args(true)
|
||||
.disable_help_flag(true)
|
||||
.infer_long_args(true);
|
||||
uucore::clap_localization::configure_localized_command(cmd)
|
||||
.args_override_self(true)
|
||||
.arg(
|
||||
Arg::new(options::HELP)
|
||||
.long(options::HELP)
|
||||
.help(translate!("chcon-help-help"))
|
||||
.action(ArgAction::Help),
|
||||
)
|
||||
.disable_help_flag(true)
|
||||
.arg(
|
||||
Arg::new(options::dereference::DEREFERENCE)
|
||||
.long(options::dereference::DEREFERENCE)
|
||||
@@ -183,6 +176,12 @@ pub fn uu_app() -> Command {
|
||||
.help(translate!("chcon-help-no-dereference"))
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("help")
|
||||
.long("help")
|
||||
.help(translate!("help"))
|
||||
.action(ArgAction::Help),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::preserve_root::PRESERVE_ROOT)
|
||||
.long(options::preserve_root::PRESERVE_ROOT)
|
||||
@@ -304,9 +303,7 @@ struct Options {
|
||||
files: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
fn parse_command_line(config: Command, args: impl uucore::Args) -> Result<Options> {
|
||||
let matches = config.get_matches_from_localized(args);
|
||||
|
||||
fn parse_command_line(matches: &ArgMatches) -> Result<Options> {
|
||||
let verbose = matches.get_flag(options::VERBOSE);
|
||||
|
||||
let (recursive_mode, affect_symlink_referent) = if matches.get_flag(options::RECURSIVE) {
|
||||
|
||||
@@ -98,12 +98,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
let cmd = Command::new(uucore::util_name())
|
||||
.version(uucore::crate_version!())
|
||||
.help_template(uucore::localized_help_template(uucore::util_name()))
|
||||
.about(translate!("chgrp-about"))
|
||||
.override_usage(format_usage(&translate!("chgrp-usage")))
|
||||
.infer_long_args(true)
|
||||
.infer_long_args(true);
|
||||
uucore::clap_localization::configure_localized_command(cmd)
|
||||
.disable_help_flag(true)
|
||||
.arg(
|
||||
Arg::new(options::HELP)
|
||||
|
||||
@@ -11,7 +11,6 @@ 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;
|
||||
@@ -111,9 +110,7 @@ fn extract_negative_modes(mut args: impl uucore::Args) -> (Option<String>, Vec<O
|
||||
#[uucore::main]
|
||||
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"))
|
||||
.get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let changes = matches.get_flag(options::CHANGES);
|
||||
let quiet = matches.get_flag(options::QUIET);
|
||||
@@ -177,13 +174,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
.version(uucore::crate_version!())
|
||||
.help_template(uucore::localized_help_template(uucore::util_name()))
|
||||
.about(translate!("chmod-about"))
|
||||
.override_usage(format_usage(&translate!("chmod-usage")))
|
||||
.help_template(uucore::localized_help_template(uucore::util_name()))
|
||||
.args_override_self(true)
|
||||
.infer_long_args(true)
|
||||
.no_binary_name(true)
|
||||
.disable_help_flag(true)
|
||||
.after_help(translate!("chmod-after-help"))
|
||||
.arg(
|
||||
Arg::new(options::HELP)
|
||||
.long(options::HELP)
|
||||
|
||||
@@ -14,7 +14,7 @@ use std::os::unix::prelude::OsStrExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process;
|
||||
use uucore::entries::{Locate, Passwd, grp2gid, usr2uid};
|
||||
use uucore::error::{UClapError, UResult, UUsageError, set_exit_code};
|
||||
use uucore::error::{UResult, UUsageError, set_exit_code};
|
||||
use uucore::fs::{MissingHandling, ResolveMode, canonicalize};
|
||||
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
|
||||
use uucore::{format_usage, show};
|
||||
@@ -155,7 +155,8 @@ impl Options {
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?;
|
||||
let matches =
|
||||
uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 125)?;
|
||||
|
||||
let default_shell: &'static str = "/bin/sh";
|
||||
let default_option: &'static str = "-i";
|
||||
@@ -234,13 +235,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
let cmd = Command::new(uucore::util_name())
|
||||
.version(uucore::crate_version!())
|
||||
.help_template(uucore::localized_help_template(uucore::util_name()))
|
||||
.about(translate!("chroot-about"))
|
||||
.override_usage(format_usage(&translate!("chroot-usage")))
|
||||
.infer_long_args(true)
|
||||
.trailing_var_arg(true)
|
||||
.trailing_var_arg(true);
|
||||
uucore::clap_localization::configure_localized_command(cmd)
|
||||
.arg(
|
||||
Arg::new(options::NEWROOT)
|
||||
.value_hint(clap::ValueHint::DirPath)
|
||||
|
||||
@@ -20,7 +20,6 @@ use uucore::checksum::{
|
||||
};
|
||||
use uucore::translate;
|
||||
|
||||
use uucore::LocalizedCommand;
|
||||
use uucore::{
|
||||
encoding,
|
||||
error::{FromIo, UResult, USimpleError},
|
||||
@@ -235,7 +234,7 @@ fn handle_tag_text_binary_flags<S: AsRef<OsStr>>(
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let check = matches.get_flag(options::CHECK);
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ use std::ffi::OsString;
|
||||
use std::fs::{File, metadata};
|
||||
use std::io::{self, BufRead, BufReader, Read, Stdin, stdin};
|
||||
use std::path::Path;
|
||||
use uucore::LocalizedCommand;
|
||||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
use uucore::format_usage;
|
||||
use uucore::fs::paths_refer_to_same_file;
|
||||
@@ -283,7 +282,7 @@ fn open_file(name: &OsString, line_ending: LineEnding) -> io::Result<LineReader>
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED));
|
||||
let filename1 = matches.get_one::<OsString>(options::FILE_1).unwrap();
|
||||
let filename2 = matches.get_one::<OsString>(options::FILE_2).unwrap();
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@ use std::os::unix::fs::{FileTypeExt, PermissionsExt};
|
||||
use std::os::unix::net::UnixListener;
|
||||
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;
|
||||
@@ -782,7 +781,7 @@ pub fn uu_app() -> Command {
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let options = Options::from_matches(&matches)?;
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ mod split_name;
|
||||
use crate::csplit_error::CsplitError;
|
||||
use crate::split_name::SplitName;
|
||||
|
||||
use uucore::LocalizedCommand;
|
||||
use uucore::translate;
|
||||
|
||||
mod options {
|
||||
@@ -606,7 +605,7 @@ where
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
// get the file to split
|
||||
let file_name = matches.get_one::<OsString>(options::FILE).unwrap();
|
||||
|
||||
@@ -18,7 +18,6 @@ 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};
|
||||
@@ -483,7 +482,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let complement = matches.get_flag(options::COMPLEMENT);
|
||||
let only_delimited = matches.get_flag(options::ONLY_DELIMITED);
|
||||
|
||||
@@ -21,7 +21,6 @@ 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
|
||||
@@ -114,7 +113,7 @@ impl From<&str> for Rfc3339Format {
|
||||
#[uucore::main]
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let format = if let Some(form) = matches.get_one::<String>(OPT_FORMAT) {
|
||||
if !form.starts_with('+') {
|
||||
|
||||
+1
-2
@@ -55,7 +55,6 @@ use nix::{
|
||||
errno::Errno,
|
||||
fcntl::{PosixFadviseAdvice, posix_fadvise},
|
||||
};
|
||||
use uucore::LocalizedCommand;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult};
|
||||
#[cfg(unix)]
|
||||
@@ -1416,7 +1415,7 @@ fn is_fifo(filename: &str) -> bool {
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
let settings: Settings = Parser::new().parse(
|
||||
matches
|
||||
|
||||
+1
-2
@@ -11,7 +11,6 @@ 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};
|
||||
@@ -407,7 +406,7 @@ impl UError for DfError {
|
||||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from_localized(args);
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user