From a0e0f7d5e3fbab27bab84bd99ddc6d6a46a101ee Mon Sep 17 00:00:00 2001 From: Ali ghahremani Date: Sat, 23 Nov 2024 13:11:32 +0330 Subject: [PATCH] fix(core): ask question before check on dependency --- cli/src/capabilities.rs | 5 +++++ core/src/viewmodel/dependency_viewmodel.rs | 11 +++++++++++ core/src/viewmodel/mod.rs | 9 +-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cli/src/capabilities.rs b/cli/src/capabilities.rs index 395126d..38a2048 100644 --- a/cli/src/capabilities.rs +++ b/cli/src/capabilities.rs @@ -22,6 +22,11 @@ impl Capabilities for CLICapabilities { } fn execute(&self, command: &str) -> bool { + self.message(Message::bake_state(format!( + "running command => '{}'\n", + command + ))); + let result = Command::new(SHELL) .arg(SWITCH) .arg(command) diff --git a/core/src/viewmodel/dependency_viewmodel.rs b/core/src/viewmodel/dependency_viewmodel.rs index cc7ebe1..2e41325 100644 --- a/core/src/viewmodel/dependency_viewmodel.rs +++ b/core/src/viewmodel/dependency_viewmodel.rs @@ -88,6 +88,17 @@ impl DependencyViewModel { return Ok(()); } + // auto yes if can't get user input + if let Some(false) = self.capabilities.ask_user_yes_no( + format!( + "'{}' is not installed, do you want to install it", + self.name() + ) + .as_str(), + ) { + return Err(format!("cancel installation {}", self.name())); + } + // *THIS IS RECURSIVE* // install dependencies of dependency first bake_view_model.install_dependencies(self.dependencies())?; diff --git a/core/src/viewmodel/mod.rs b/core/src/viewmodel/mod.rs index 5a2e783..d993610 100644 --- a/core/src/viewmodel/mod.rs +++ b/core/src/viewmodel/mod.rs @@ -85,7 +85,7 @@ impl BakeViewModel { self.dependencies.values().collect() } - /// Same as [install_dependencies] but in loop + /// Same as [install_dependency] but in loop /// It will stop iteration on error pub fn install_dependencies(&self, names: &[String]) -> Result<(), String> { for name in names { @@ -97,13 +97,6 @@ impl BakeViewModel { /// this installs dependencies and will skip if it's already installed pub fn install_dependency(&self, name: &str) -> Result<(), String> { if let Some(dependency) = self.get_dependency(name) { - // auto yes if can't get user input - if let Some(false) = self.caps.ask_user_yes_no( - format!("'{}' is not installed, do you want to install it", name).as_str(), - ) { - return Err(format!("cancel installation {}", name)); - } - dependency.try_install(self) } else { Err(format!("dependency {} not found", name))