From ab898e40b09fb33d4e2aa80cf2065480168dfbc7 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Mon, 19 May 2025 13:20:00 -0500 Subject: [PATCH] Move get_config() to a method of Cli We were already basically using it as a method. All inputs to the function were a function of the CLI arguments anyway. Signed-off-by: Tristan Partin --- compute_tools/src/bin/compute_ctl.rs | 51 +++++++++++++++------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/compute_tools/src/bin/compute_ctl.rs b/compute_tools/src/bin/compute_ctl.rs index 8b502a058e..5dd8ca4499 100644 --- a/compute_tools/src/bin/compute_ctl.rs +++ b/compute_tools/src/bin/compute_ctl.rs @@ -145,6 +145,33 @@ impl Cli { } } +impl Cli { + pub fn get_config(&self) -> Result { + // First, read the config from the path if provided + if let Some(ref config) = self.config { + let file = File::open(config)?; + return Ok(serde_json::from_reader(&file)?); + } + + // If the config wasn't provided in the CLI arguments, then retrieve it from + // the control plane + match get_config_from_control_plane( + self.control_plane_uri.as_ref().unwrap(), + &self.compute_id, + ) { + Ok(config) => Ok(config), + Err(e) => { + error!( + "cannot get response from control plane: {}\n\ + neither spec nor confirmation that compute is in the Empty state was received", + e + ); + Err(e) + } + } + } +} + fn main() -> Result<()> { let cli = Cli::parse(); @@ -166,7 +193,7 @@ fn main() -> Result<()> { let connstr = Url::parse(&cli.connstr).context("cannot parse connstr as a URL")?; - let config = get_config(&cli)?; + let config = cli.get_config()?; let compute_node = ComputeNode::new( ComputeNodeParams { @@ -213,28 +240,6 @@ async fn init() -> Result<()> { Ok(()) } -fn get_config(cli: &Cli) -> Result { - // First, read the config from the path if provided - if let Some(ref config) = cli.config { - let file = File::open(config)?; - return Ok(serde_json::from_reader(&file)?); - } - - // If the config wasn't provided in the CLI arguments, then retrieve it from - // the control plane - match get_config_from_control_plane(cli.control_plane_uri.as_ref().unwrap(), &cli.compute_id) { - Ok(config) => Ok(config), - Err(e) => { - error!( - "cannot get response from control plane: {}\n\ - neither spec nor confirmation that compute is in the Empty state was received", - e - ); - Err(e) - } - } -} - fn deinit_and_exit(exit_code: Option) -> ! { // Shutdown trace pipeline gracefully, so that it has a chance to send any // pending traces before we exit. Shutting down OTEL tracing provider may