Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"**/*.svg",
"src/uu/*/locales/*.ftl",
"src/uucore/locales/*.ftl",
".devcontainer/**"
".devcontainer/**",
"util/gnu-patches/**",
],

"enableGlobDot": true,
Expand Down
9 changes: 9 additions & 0 deletions .vscode/cspell.dictionaries/workspace.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,12 @@ getcwd
# * other
weblate
algs

# translation tests
CLICOLOR
erreur
Utilisation
merror
merreur
verbo
inattendu
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/uu/arch/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))?;
Expand Down
9 changes: 4 additions & 5 deletions src/uu/base32/src/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for splitting the setup of command into two parts? Why not doing the localization at the end?

// Format arguments.
.arg(
Arg::new(options::DECODE)
Expand Down
3 changes: 1 addition & 2 deletions src/uu/basename/src/basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));

Expand Down
5 changes: 1 addition & 4 deletions src/uu/basenc/src/basenc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/uu/cat/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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
Expand Down
31 changes: 14 additions & 17 deletions src/uu/chcon/src/chcon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for splitting the setup of command into two parts? Why not doing the localization at the end?

.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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/uu/chgrp/src/chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for splitting the setup of command into two parts? Why not doing the localization at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a follow up change? it was easier this way with all the init steps

.disable_help_flag(true)
.arg(
Arg::new(options::HELP)
Expand Down
8 changes: 3 additions & 5 deletions src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions src/uu/chroot/src/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for splitting the setup of command into two parts? Why not doing the localization at the end?

.arg(
Arg::new(options::NEWROOT)
.value_hint(clap::ValueHint::DirPath)
Expand Down
3 changes: 1 addition & 2 deletions src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use uucore::checksum::{
};
use uucore::translate;

use uucore::LocalizedCommand;
use uucore::{
encoding,
error::{FromIo, UResult, USimpleError},
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/uu/comm/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;

Expand Down
3 changes: 1 addition & 2 deletions src/uu/csplit/src/csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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('+') {
Expand Down
Loading
Loading