From 221bd5a5c9cd5cb062a8ad47ba9141448484c512 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Mon, 13 May 2024 10:18:48 -0500 Subject: [PATCH] lazily configure the warg client, only if a registry package is being used --- src/commands/plug.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands/plug.rs b/src/commands/plug.rs index d0ebaa5..5b2d0d0 100644 --- a/src/commands/plug.rs +++ b/src/commands/plug.rs @@ -99,12 +99,17 @@ impl PlugCommand { let mut graph = CompositionGraph::new(); #[cfg(feature = "registry")] - let client = FileSystemClient::new_with_default_config(self.registry.as_deref()).ok(); + let mut client = None; let socket_path = match &self.socket { #[cfg(feature = "registry")] PackageRef::RegistryPackage((name, version)) => { - let client = client.as_ref().ok_or_else(|| { + if client.is_none() { + client = Some(FileSystemClient::new_with_default_config( + self.registry.as_deref(), + )); + } + let client = client.as_ref().unwrap().as_ref().map_err(|_| { anyhow::anyhow!( "Warg registry is not configured. Package `{name}` was not found." ) @@ -170,7 +175,12 @@ impl PlugCommand { let (mut name, path) = match plug_ref { #[cfg(feature = "registry")] PackageRef::RegistryPackage((name, version)) => { - let client = client.as_ref().ok_or_else(|| { + if client.is_none() { + client = Some(FileSystemClient::new_with_default_config( + self.registry.as_deref(), + )); + } + let client = client.as_ref().unwrap().as_ref().map_err(|_| { anyhow::anyhow!( "Warg registry is not configured. Package `{name}` was not found." )