-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
clap/locale: fix the colors for all programs (Closes: #8501) #8542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,3 +349,12 @@ getcwd | |
# * other | ||
weblate | ||
algs | ||
|
||
# translation tests | ||
CLICOLOR | ||
erreur | ||
Utilisation | ||
merror | ||
merreur | ||
verbo | ||
inattendu |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment.
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?