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>, + color_arg: Option>, ) -> 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(()) } 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), - /* 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/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>, + /// Value of all the `--color` argument, if any. + color: Option>, /// Value of the `-R` or `--repository` argument, if any. repo: Option>, /// Value of the `--cwd` argument, if any. @@ -536,6 +546,7 @@ fn parse(args: impl IntoIterator) -> 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, + } } }