From 6abded8ff574acee92c3e0fd5046880da80b9c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Kr=C3=BCger?= Date: Thu, 4 Jul 2024 16:53:55 +0200 Subject: [PATCH] fix(cli): Always respect the `--metrics-port disabled` option --- iroh-cli/src/commands.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/iroh-cli/src/commands.rs b/iroh-cli/src/commands.rs index a9e8d44cdf..d32d09bb78 100644 --- a/iroh-cli/src/commands.rs +++ b/iroh-cli/src/commands.rs @@ -117,7 +117,7 @@ impl Cli { Commands::Console => { let data_dir_owned = data_dir.to_owned(); if self.start { - let config = NodeConfig::load(self.config.as_deref()).await?; + let config = Self::load_config(self.config, self.metrics_port).await?; start::run_with_command( &config, data_dir, @@ -138,7 +138,7 @@ impl Cli { Commands::Rpc(command) => { let data_dir_owned = data_dir.to_owned(); if self.start { - let config = NodeConfig::load(self.config.as_deref()).await?; + let config = Self::load_config(self.config, self.metrics_port).await?; start::run_with_command( &config, data_dir, @@ -165,13 +165,7 @@ impl Cli { path.display() ); } - let mut config = NodeConfig::load(self.config.as_deref()).await?; - if let Some(metrics_port) = self.metrics_port { - config.metrics_addr = match metrics_port { - MetricsPort::Disabled => None, - MetricsPort::Port(port) => Some(([127, 0, 0, 1], port).into()), - }; - } + let config = Self::load_config(self.config, self.metrics_port).await?; let add_command = add.map(|source| blob::BlobCommands::Add { source, @@ -192,15 +186,23 @@ impl Cli { .await } Commands::Doctor { command } => { - let mut config = NodeConfig::load(self.config.as_deref()).await?; - if let Some(metrics_port) = self.metrics_port { - config.metrics_addr = match metrics_port { - MetricsPort::Disabled => None, - MetricsPort::Port(port) => Some(([127, 0, 0, 1], port).into()), - }; - } + let config = Self::load_config(self.config, self.metrics_port).await?; self::doctor::run(command, &config).await } } } + + async fn load_config( + config: Option, + metrics_port: Option, + ) -> Result { + let mut config = NodeConfig::load(config.as_deref()).await?; + if let Some(metrics_port) = metrics_port { + config.metrics_addr = match metrics_port { + MetricsPort::Disabled => None, + MetricsPort::Port(port) => Some(([127, 0, 0, 1], port).into()), + }; + } + Ok(config) + } }