[Updated] D12166: rhg: Add parsing for the --color global CLI argument
SimonSapin
phabricator at mercurial-scm.org
Mon Feb 14 10:25:39 UTC 2022
Closed by commit rHGd4a5c2197208: rhg: Add parsing for the --color global CLI argument (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D12166?vs=32152&id=32158
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D12166/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D12166
AFFECTED FILES
rust/hg-core/src/config/config.rs
rust/hg-core/src/config/layer.rs
rust/rhg/src/main.rs
CHANGE DETAILS
diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -66,6 +66,14 @@
.takes_value(true)
.global(true),
)
+ .arg(
+ Arg::with_name("color")
+ .help("when to colorize (boolean, always, auto, never, or debug)")
+ .long("--color")
+ .value_name("TYPE")
+ .takes_value(true)
+ .global(true),
+ )
.version("0.0.1");
let app = add_subcommand_args(app);
@@ -179,7 +187,7 @@
});
non_repo_config
- .load_cli_args_config(early_args.config)
+ .load_cli_args(early_args.config, early_args.color)
.unwrap_or_else(|error| {
exit(
&initial_current_dir,
@@ -526,6 +534,8 @@
struct EarlyArgs {
/// Values of all `--config` arguments. (Possibly none)
config: Vec<Vec<u8>>,
+ /// Value of all the `--color` argument, if any.
+ color: Option<Vec<u8>>,
/// Value of the `-R` or `--repository` argument, if any.
repo: Option<Vec<u8>>,
/// Value of the `--cwd` argument, if any.
@@ -536,6 +546,7 @@
fn parse(args: impl IntoIterator<Item = OsString>) -> Self {
let mut args = args.into_iter().map(get_bytes_from_os_str);
let mut config = Vec::new();
+ let mut color = None;
let mut repo = None;
let mut cwd = None;
// Use `while let` instead of `for` so that we can also call
@@ -549,6 +560,14 @@
config.push(value.to_owned())
}
+ if arg == b"--color" {
+ if let Some(value) = args.next() {
+ color = Some(value)
+ }
+ } else if let Some(value) = arg.drop_prefix(b"--color=") {
+ color = Some(value.to_owned())
+ }
+
if arg == b"--cwd" {
if let Some(value) = args.next() {
cwd = Some(value)
@@ -567,7 +586,12 @@
repo = Some(value.to_owned())
}
}
- Self { config, repo, cwd }
+ Self {
+ config,
+ color,
+ repo,
+ cwd,
+ }
}
}
diff --git a/rust/hg-core/src/config/layer.rs b/rust/hg-core/src/config/layer.rs
--- a/rust/hg-core/src/config/layer.rs
+++ b/rust/hg-core/src/config/layer.rs
@@ -301,10 +301,11 @@
File(PathBuf),
/// From a `--config` CLI argument
CommandLine,
+ /// From a `--color` CLI argument
+ CommandLineColor,
/// From environment variables like `$PAGER` or `$EDITOR`
Environment(Vec<u8>),
- /* TODO cli
- * TODO defaults (configitems.py)
+ /* TODO defaults (configitems.py)
* TODO extensions
* TODO Python resources?
* Others? */
@@ -318,6 +319,7 @@
match self {
ConfigOrigin::File(p) => out.write_all(&get_bytes_from_path(p)),
ConfigOrigin::CommandLine => out.write_all(b"--config"),
+ ConfigOrigin::CommandLineColor => out.write_all(b"--color"),
ConfigOrigin::Environment(e) => write_bytes!(out, b"${}", e),
}
}
diff --git a/rust/hg-core/src/config/config.rs b/rust/hg-core/src/config/config.rs
--- a/rust/hg-core/src/config/config.rs
+++ b/rust/hg-core/src/config/config.rs
@@ -139,13 +139,19 @@
Ok(config)
}
- pub fn load_cli_args_config(
+ pub fn load_cli_args(
&mut self,
cli_config_args: impl IntoIterator<Item = impl AsRef<[u8]>>,
+ color_arg: Option<Vec<u8>>,
) -> Result<(), ConfigError> {
if let Some(layer) = ConfigLayer::parse_cli_args(cli_config_args)? {
self.layers.push(layer)
}
+ if let Some(arg) = color_arg {
+ let mut layer = ConfigLayer::new(ConfigOrigin::CommandLineColor);
+ layer.add(b"ui"[..].into(), b"color"[..].into(), arg, None);
+ self.layers.push(layer)
+ }
Ok(())
}
To: SimonSapin, #hg-reviewers, Alphare
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220214/bbd3e7e0/attachment-0002.html>
More information about the Mercurial-patches
mailing list