Skip to content

Commit

Permalink
feat(cmd): rename command to get available plugins in a remote
Browse files Browse the repository at this point in the history
This commit changes the CLI command to get available plugins in a remote repository in coffee.
Previously the user had to run `coffee remote <repository_name> --plugins` which was confusing. This commit changes it to be `coffee remote inspect <repository_name>` and updates documentation.

Signed-off-by: Tarek <tareknaser360@gmail.com>
  • Loading branch information
tareknaser committed Apr 14, 2024
1 parent 102ab94 commit 9343206
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 67 deletions.
15 changes: 6 additions & 9 deletions coffee_cmd/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ pub enum CoffeeCommand {
Remote {
#[clap(subcommand)]
action: Option<RemoteAction>,
#[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<String>,
},
Expand Down Expand Up @@ -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 {},
}
Expand All @@ -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()),
Expand All @@ -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,
}
}
Expand Down
106 changes: 50 additions & 56 deletions coffee_cmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion coffee_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum CoffeeOperation {
Upgrade(String, bool),
Remove(String),
/// Remote(name repository, url of the repository)
Remote(Option<RemoteAction>, bool, Option<String>),
Remote(Option<RemoteAction>, Option<String>),
/// Setup(core lightning root path)
Setup(String),
Show(String),
Expand All @@ -36,6 +36,7 @@ pub enum CoffeeOperation {
pub enum RemoteAction {
Add(String, String),
Rm(String),
Inspect(String),
List,
}

Expand Down
2 changes: 1 addition & 1 deletion docs/docs-book/src/using-coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ To list available plugins in a specific remote repository
> ✅ Implemented
```bash
coffee remote <repository_name> --plugins
coffee remote inspect <repository_name>
```

### Install a Plugin
Expand Down

0 comments on commit 9343206

Please sign in to comment.