diff rust/hg-core/src/config/config.rs @ 46504:2e5dd18d6dc3

rhg: Add support for --config CLI arguments Differential Revision: https://phab.mercurial-scm.org/D9971
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 08 Feb 2021 23:08:44 +0100
parents eace48b4a786
children d2e61f00ee9d
line wrap: on
line diff
--- a/rust/hg-core/src/config/config.rs	Mon Feb 08 21:37:30 2021 +0100
+++ b/rust/hg-core/src/config/config.rs	Mon Feb 08 23:08:44 2021 +0100
@@ -65,9 +65,9 @@
     /// Load system and user configuration from various files.
     ///
     /// This is also affected by some environment variables.
-    ///
-    /// TODO: add a parameter for `--config` CLI arguments
-    pub fn load() -> Result<Self, ConfigError> {
+    pub fn load(
+        cli_config_args: impl IntoIterator<Item = impl AsRef<[u8]>>,
+    ) -> Result<Self, ConfigError> {
         let mut config = Self { layers: Vec::new() };
         let opt_rc_path = env::var_os("HGRCPATH");
         // HGRCPATH replaces system config
@@ -92,6 +92,9 @@
                 }
             }
         }
+        if let Some(layer) = ConfigLayer::parse_cli_args(cli_config_args)? {
+            config.layers.push(layer)
+        }
         Ok(config)
     }