From 516f620f35d55d3d15140eea9b61379af1b9d02d Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Sat, 30 Dec 2023 00:05:26 +0530 Subject: [PATCH] feat: verbose to upgrade feat: add verbose flag to upgrade fix: lint check feat: upgrade spinner fix: minor bugs/comments --- coffee_cmd/src/cmd.rs | 8 +++++-- coffee_cmd/src/main.rs | 37 +++++++++++++++++++++----------- coffee_core/src/coffee.rs | 5 ++--- coffee_core/src/lib.rs | 4 ++-- coffee_lib/src/plugin.rs | 2 +- coffee_lib/src/plugin_manager.rs | 2 +- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/coffee_cmd/src/cmd.rs b/coffee_cmd/src/cmd.rs index fd3a3f9b..0807d155 100644 --- a/coffee_cmd/src/cmd.rs +++ b/coffee_cmd/src/cmd.rs @@ -32,7 +32,11 @@ pub enum CoffeeCommand { }, /// upgrade a single repository. #[clap(arg_required_else_help = true)] - Upgrade { repo: String }, + Upgrade { + repo: String, + #[arg(short, long, action = clap::ArgAction::SetTrue)] + verbose: bool, + }, /// Print the list of plugins installed in cln. #[clap(arg_required_else_help = false)] List {}, @@ -86,7 +90,7 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation { verbose, dynamic, } => Self::Install(plugin.to_owned(), *verbose, *dynamic), - CoffeeCommand::Upgrade { repo } => Self::Upgrade(repo.to_owned()), + CoffeeCommand::Upgrade { repo, verbose } => Self::Upgrade(repo.to_owned(), *verbose), CoffeeCommand::List {} => Self::List, CoffeeCommand::Setup { cln_conf } => Self::Setup(cln_conf.to_owned()), CoffeeCommand::Remote { diff --git a/coffee_cmd/src/main.rs b/coffee_cmd/src/main.rs index 30d51cfd..d8dff966 100644 --- a/coffee_cmd/src/main.rs +++ b/coffee_cmd/src/main.rs @@ -57,20 +57,31 @@ async fn main() -> Result<(), CoffeeError> { let remotes = coffee.list().await; coffee_term::show_list(remotes) } - CoffeeCommand::Upgrade { repo } => { - match coffee.upgrade(&repo).await { - Ok(res) => match res.status { - UpgradeStatus::UpToDate => { - term::info!("Remote repository `{}` is already up to date!", res.repo) - } - UpgradeStatus::Updated => { - term::success!( - "Remote repository `{}` was successfully upgraded!", - res.repo - ) + CoffeeCommand::Upgrade { repo, verbose } => { + let spinner = if !verbose { + Some(term::spinner("Upgrading")) + } else { + None + }; + match coffee.upgrade(&repo, verbose).await { + Ok(res) => { + spinner.and_then(|splinner| Some(splinner.finish())); + match res.status { + UpgradeStatus::UpToDate => { + term::info!("Remote repository `{}` is already up to date!", res.repo) + } + UpgradeStatus::Updated => { + term::success!( + "Remote repository `{}` was successfully upgraded!", + res.repo + ) + } } - }, - Err(err) => return Err(err), + } + Err(err) => { + spinner.and_then(|spinner| Some(spinner.failed())); + return Err(err); + } } Ok(()) } diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 6b087799..fbaef745 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -334,7 +334,7 @@ impl PluginManager for CoffeeManager { }) } - async fn upgrade(&mut self, repo: &str) -> Result { + async fn upgrade(&mut self, repo: &str, verbose: bool) -> Result { // TODO: upgrade should now be able to upgrade a single plugin // without affecting other plugins installed from the same repo let repository = self @@ -345,8 +345,7 @@ impl PluginManager for CoffeeManager { let status = repository.upgrade(&self.config.plugins).await?; for plugins in status.plugins_effected.iter() { self.remove(plugins).await?; - // FIXME: pass the verbose flag to the upgrade command - self.install(plugins, false, false).await?; + self.install(plugins, verbose, false).await?; } self.flush().await?; Ok(status) diff --git a/coffee_core/src/lib.rs b/coffee_core/src/lib.rs index da3a6cb6..4f0c5292 100644 --- a/coffee_core/src/lib.rs +++ b/coffee_core/src/lib.rs @@ -11,8 +11,8 @@ pub enum CoffeeOperation { Install(String, bool, bool), /// List List, - // Upgrade(name of the repository) - Upgrade(String), + // Upgrade(name of the repository, verbose run) + Upgrade(String, bool), Remove(String), /// Remote(name repository, url of the repository) Remote(Option, bool, Option), diff --git a/coffee_lib/src/plugin.rs b/coffee_lib/src/plugin.rs index 897ed711..a8f2f406 100644 --- a/coffee_lib/src/plugin.rs +++ b/coffee_lib/src/plugin.rs @@ -149,7 +149,7 @@ impl Plugin { } /// upgrade the plugin to a new version. - pub async fn upgrade(&mut self) -> Result<(), CoffeeError> { + pub async fn upgrade(&mut self, _: bool) -> Result<(), CoffeeError> { todo!("not implemented yet") } diff --git a/coffee_lib/src/plugin_manager.rs b/coffee_lib/src/plugin_manager.rs index 7ae5fcc2..ba40e475 100644 --- a/coffee_lib/src/plugin_manager.rs +++ b/coffee_lib/src/plugin_manager.rs @@ -25,7 +25,7 @@ pub trait PluginManager { async fn list(&mut self) -> Result; /// upgrade a single or multiple repositories. - async fn upgrade(&mut self, repo: &str) -> Result; + async fn upgrade(&mut self, repo: &str, verbose: bool) -> Result; /// add the remote repository to the plugin manager. async fn add_remote(&mut self, name: &str, url: &str) -> Result<(), CoffeeError>;