From db419c68b6c75520abcdc6142f6171dde98ead4a Mon Sep 17 00:00:00 2001 From: Tarek Date: Sun, 14 Apr 2024 11:00:56 +0200 Subject: [PATCH] feat(cmd): rename command to get available plugins in a remote This commit changes the CLI command to get available plugins in a remote repository in coffee. Previously the user had to run `coffee remote --plugins` which was confusing. This commit changes it to be `coffee remote inspect ` and updates documentation. Signed-off-by: Tarek --- coffee_cmd/src/cmd.rs | 15 ++-- coffee_cmd/src/main.rs | 106 ++++++++++++++--------------- coffee_core/src/lib.rs | 3 +- docs/docs-book/src/using-coffee.md | 2 +- 4 files changed, 59 insertions(+), 67 deletions(-) diff --git a/coffee_cmd/src/cmd.rs b/coffee_cmd/src/cmd.rs index cf1a474..702b90c 100644 --- a/coffee_cmd/src/cmd.rs +++ b/coffee_cmd/src/cmd.rs @@ -48,8 +48,6 @@ pub enum CoffeeCommand { Remote { #[clap(subcommand)] action: Option, - #[arg(short, long, action = clap::ArgAction::SetTrue, requires = "remote-name")] - plugins: bool, #[arg(name = "remote-name", help = "The name of the remote repository")] name: Option, }, @@ -87,6 +85,8 @@ pub enum RemoteAction { Add { name: String, url: String }, /// Remove a remote repository from the plugin manager. Rm { name: String }, + /// Inspect the plugins available in a remote repository. + Inspect { name: String }, /// List the remote repositories from the plugin manager. List {}, } @@ -102,15 +102,11 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation { 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 { - action, - plugins, - name, - } => { + CoffeeCommand::Remote { action, name } => { if let Some(action) = action { - return Self::Remote(Some(action.into()), *plugins, name.clone()); + return Self::Remote(Some(action.into()), name.clone()); } - Self::Remote(None, *plugins, name.clone()) + Self::Remote(None, name.clone()) } CoffeeCommand::Remove { plugin } => Self::Remove(plugin.to_owned()), CoffeeCommand::Show { plugin } => Self::Show(plugin.to_owned()), @@ -131,6 +127,7 @@ impl From<&RemoteAction> for coffee_core::RemoteAction { match value { RemoteAction::Add { name, url } => Self::Add(name.to_owned(), url.to_owned()), RemoteAction::Rm { name } => Self::Rm(name.to_owned()), + RemoteAction::Inspect { name } => Self::Inspect(name.to_owned()), RemoteAction::List {} => Self::List, } } diff --git a/coffee_cmd/src/main.rs b/coffee_cmd/src/main.rs index 6201e1d..c64106e 100644 --- a/coffee_cmd/src/main.rs +++ b/coffee_cmd/src/main.rs @@ -78,65 +78,59 @@ async fn run(args: CoffeeArgs, mut coffee: CoffeeManager) -> Result<(), CoffeeEr } } } - CoffeeCommand::Remote { - action, - plugins, - name, - } => { - if plugins { - let result = coffee.get_plugins_in_remote(&name.unwrap()).await; - coffee_term::show_list(result)?; - } else { - match action { - Some(RemoteAction::Add { name, url }) => { - let mut spinner = term::spinner(format!("Fetch remote from {url}")); - let result = coffee.add_remote(&name, &url).await; - if let Err(err) = &result { - spinner.error(format!("Error while add remote: {err}")); - return result; - } - spinner.message("Remote added!"); - spinner.finish(); - } - Some(RemoteAction::Rm { name }) => { - let mut spinner = term::spinner(format!("Removing remote {name}")); - let result = coffee.rm_remote(&name).await; - if let Err(err) = &result { - spinner.error(format!("Error while removing the repository: {err}")); - return result; - } - spinner.message("Remote removed!"); - spinner.finish(); + CoffeeCommand::Remote { action, name } => { + match action { + Some(RemoteAction::Add { name, url }) => { + let mut spinner = term::spinner(format!("Fetch remote from {url}")); + let result = coffee.add_remote(&name, &url).await; + if let Err(err) = &result { + spinner.error(format!("Error while add remote: {err}")); + return result; } - Some(RemoteAction::List {}) => { - let remotes = coffee.list_remotes().await; - coffee_term::show_remote_list(remotes)?; + spinner.message("Remote added!"); + spinner.finish(); + } + Some(RemoteAction::Rm { name }) => { + let mut spinner = term::spinner(format!("Removing remote {name}")); + let result = coffee.rm_remote(&name).await; + if let Err(err) = &result { + spinner.error(format!("Error while removing the repository: {err}")); + return result; } - None => { - // This is the case when the user does not provides the - // plugins flag, so we just show the remote repository - // information + spinner.message("Remote removed!"); + spinner.finish(); + } + Some(RemoteAction::Inspect { name }) => { + let result = coffee.get_plugins_in_remote(&name).await; + coffee_term::show_list(result)?; + } + Some(RemoteAction::List {}) => { + let remotes = coffee.list_remotes().await; + coffee_term::show_remote_list(remotes)?; + } + None => { + // This is the case when the user does not provides the + // plugins flag, so we just show the remote repository + // information - // The name will be always Some because of the - // arg_required_else_help = true in the clap - // attribute - let name = - name.ok_or_else(|| error!("No remote repository name provided"))?; - let remotes = coffee.list_remotes().await?; - let remotes = remotes - .remotes - .ok_or_else(|| error!("Couldn't get the remote repositories"))?; - let remote = remotes - .iter() - .find(|remote| remote.local_name == name) - .ok_or_else(|| error!("Couldn't find the remote repository"))?; - // A workaround to show the remote repository information - // in the same way as the list command - let remote = Ok(CoffeeRemote { - remotes: Some(vec![remote.clone()]), - }); - coffee_term::show_remote_list(remote)?; - } + // The name will be always Some because of the + // arg_required_else_help = true in the clap + // attribute + let name = name.ok_or_else(|| error!("No remote repository name provided"))?; + let remotes = coffee.list_remotes().await?; + let remotes = remotes + .remotes + .ok_or_else(|| error!("Couldn't get the remote repositories"))?; + let remote = remotes + .iter() + .find(|remote| remote.local_name == name) + .ok_or_else(|| error!("Couldn't find the remote repository"))?; + // A workaround to show the remote repository information + // in the same way as the list command + let remote = Ok(CoffeeRemote { + remotes: Some(vec![remote.clone()]), + }); + coffee_term::show_remote_list(remote)?; } } } diff --git a/coffee_core/src/lib.rs b/coffee_core/src/lib.rs index d237d49..9629f58 100644 --- a/coffee_core/src/lib.rs +++ b/coffee_core/src/lib.rs @@ -15,7 +15,7 @@ pub enum CoffeeOperation { Upgrade(String, bool), Remove(String), /// Remote(name repository, url of the repository) - Remote(Option, bool, Option), + Remote(Option, Option), /// Setup(core lightning root path) Setup(String), Show(String), @@ -36,6 +36,7 @@ pub enum CoffeeOperation { pub enum RemoteAction { Add(String, String), Rm(String), + Inspect(String), List, } diff --git a/docs/docs-book/src/using-coffee.md b/docs/docs-book/src/using-coffee.md index 4a7e0d4..7a5b75a 100644 --- a/docs/docs-book/src/using-coffee.md +++ b/docs/docs-book/src/using-coffee.md @@ -74,7 +74,7 @@ To list available plugins in a specific remote repository > ✅ Implemented ```bash -coffee remote --plugins +coffee remote inspect ``` ### Install a Plugin