Skip to content

Commit db419c6

Browse files
tareknaservincenzopalazzo
authored andcommitted
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 <repository_name> --plugins` which was confusing. This commit changes it to be `coffee remote inspect <repository_name>` and updates documentation. Signed-off-by: Tarek <[email protected]>
1 parent 102ab94 commit db419c6

File tree

4 files changed

+59
-67
lines changed

4 files changed

+59
-67
lines changed

coffee_cmd/src/cmd.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ pub enum CoffeeCommand {
4848
Remote {
4949
#[clap(subcommand)]
5050
action: Option<RemoteAction>,
51-
#[arg(short, long, action = clap::ArgAction::SetTrue, requires = "remote-name")]
52-
plugins: bool,
5351
#[arg(name = "remote-name", help = "The name of the remote repository")]
5452
name: Option<String>,
5553
},
@@ -87,6 +85,8 @@ pub enum RemoteAction {
8785
Add { name: String, url: String },
8886
/// Remove a remote repository from the plugin manager.
8987
Rm { name: String },
88+
/// Inspect the plugins available in a remote repository.
89+
Inspect { name: String },
9090
/// List the remote repositories from the plugin manager.
9191
List {},
9292
}
@@ -102,15 +102,11 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation {
102102
CoffeeCommand::Upgrade { repo, verbose } => Self::Upgrade(repo.to_owned(), *verbose),
103103
CoffeeCommand::List {} => Self::List,
104104
CoffeeCommand::Setup { cln_conf } => Self::Setup(cln_conf.to_owned()),
105-
CoffeeCommand::Remote {
106-
action,
107-
plugins,
108-
name,
109-
} => {
105+
CoffeeCommand::Remote { action, name } => {
110106
if let Some(action) = action {
111-
return Self::Remote(Some(action.into()), *plugins, name.clone());
107+
return Self::Remote(Some(action.into()), name.clone());
112108
}
113-
Self::Remote(None, *plugins, name.clone())
109+
Self::Remote(None, name.clone())
114110
}
115111
CoffeeCommand::Remove { plugin } => Self::Remove(plugin.to_owned()),
116112
CoffeeCommand::Show { plugin } => Self::Show(plugin.to_owned()),
@@ -131,6 +127,7 @@ impl From<&RemoteAction> for coffee_core::RemoteAction {
131127
match value {
132128
RemoteAction::Add { name, url } => Self::Add(name.to_owned(), url.to_owned()),
133129
RemoteAction::Rm { name } => Self::Rm(name.to_owned()),
130+
RemoteAction::Inspect { name } => Self::Inspect(name.to_owned()),
134131
RemoteAction::List {} => Self::List,
135132
}
136133
}

coffee_cmd/src/main.rs

+50-56
Original file line numberDiff line numberDiff line change
@@ -78,65 +78,59 @@ async fn run(args: CoffeeArgs, mut coffee: CoffeeManager) -> Result<(), CoffeeEr
7878
}
7979
}
8080
}
81-
CoffeeCommand::Remote {
82-
action,
83-
plugins,
84-
name,
85-
} => {
86-
if plugins {
87-
let result = coffee.get_plugins_in_remote(&name.unwrap()).await;
88-
coffee_term::show_list(result)?;
89-
} else {
90-
match action {
91-
Some(RemoteAction::Add { name, url }) => {
92-
let mut spinner = term::spinner(format!("Fetch remote from {url}"));
93-
let result = coffee.add_remote(&name, &url).await;
94-
if let Err(err) = &result {
95-
spinner.error(format!("Error while add remote: {err}"));
96-
return result;
97-
}
98-
spinner.message("Remote added!");
99-
spinner.finish();
100-
}
101-
Some(RemoteAction::Rm { name }) => {
102-
let mut spinner = term::spinner(format!("Removing remote {name}"));
103-
let result = coffee.rm_remote(&name).await;
104-
if let Err(err) = &result {
105-
spinner.error(format!("Error while removing the repository: {err}"));
106-
return result;
107-
}
108-
spinner.message("Remote removed!");
109-
spinner.finish();
81+
CoffeeCommand::Remote { action, name } => {
82+
match action {
83+
Some(RemoteAction::Add { name, url }) => {
84+
let mut spinner = term::spinner(format!("Fetch remote from {url}"));
85+
let result = coffee.add_remote(&name, &url).await;
86+
if let Err(err) = &result {
87+
spinner.error(format!("Error while add remote: {err}"));
88+
return result;
11089
}
111-
Some(RemoteAction::List {}) => {
112-
let remotes = coffee.list_remotes().await;
113-
coffee_term::show_remote_list(remotes)?;
90+
spinner.message("Remote added!");
91+
spinner.finish();
92+
}
93+
Some(RemoteAction::Rm { name }) => {
94+
let mut spinner = term::spinner(format!("Removing remote {name}"));
95+
let result = coffee.rm_remote(&name).await;
96+
if let Err(err) = &result {
97+
spinner.error(format!("Error while removing the repository: {err}"));
98+
return result;
11499
}
115-
None => {
116-
// This is the case when the user does not provides the
117-
// plugins flag, so we just show the remote repository
118-
// information
100+
spinner.message("Remote removed!");
101+
spinner.finish();
102+
}
103+
Some(RemoteAction::Inspect { name }) => {
104+
let result = coffee.get_plugins_in_remote(&name).await;
105+
coffee_term::show_list(result)?;
106+
}
107+
Some(RemoteAction::List {}) => {
108+
let remotes = coffee.list_remotes().await;
109+
coffee_term::show_remote_list(remotes)?;
110+
}
111+
None => {
112+
// This is the case when the user does not provides the
113+
// plugins flag, so we just show the remote repository
114+
// information
119115

120-
// The name will be always Some because of the
121-
// arg_required_else_help = true in the clap
122-
// attribute
123-
let name =
124-
name.ok_or_else(|| error!("No remote repository name provided"))?;
125-
let remotes = coffee.list_remotes().await?;
126-
let remotes = remotes
127-
.remotes
128-
.ok_or_else(|| error!("Couldn't get the remote repositories"))?;
129-
let remote = remotes
130-
.iter()
131-
.find(|remote| remote.local_name == name)
132-
.ok_or_else(|| error!("Couldn't find the remote repository"))?;
133-
// A workaround to show the remote repository information
134-
// in the same way as the list command
135-
let remote = Ok(CoffeeRemote {
136-
remotes: Some(vec![remote.clone()]),
137-
});
138-
coffee_term::show_remote_list(remote)?;
139-
}
116+
// The name will be always Some because of the
117+
// arg_required_else_help = true in the clap
118+
// attribute
119+
let name = name.ok_or_else(|| error!("No remote repository name provided"))?;
120+
let remotes = coffee.list_remotes().await?;
121+
let remotes = remotes
122+
.remotes
123+
.ok_or_else(|| error!("Couldn't get the remote repositories"))?;
124+
let remote = remotes
125+
.iter()
126+
.find(|remote| remote.local_name == name)
127+
.ok_or_else(|| error!("Couldn't find the remote repository"))?;
128+
// A workaround to show the remote repository information
129+
// in the same way as the list command
130+
let remote = Ok(CoffeeRemote {
131+
remotes: Some(vec![remote.clone()]),
132+
});
133+
coffee_term::show_remote_list(remote)?;
140134
}
141135
}
142136
}

coffee_core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub enum CoffeeOperation {
1515
Upgrade(String, bool),
1616
Remove(String),
1717
/// Remote(name repository, url of the repository)
18-
Remote(Option<RemoteAction>, bool, Option<String>),
18+
Remote(Option<RemoteAction>, Option<String>),
1919
/// Setup(core lightning root path)
2020
Setup(String),
2121
Show(String),
@@ -36,6 +36,7 @@ pub enum CoffeeOperation {
3636
pub enum RemoteAction {
3737
Add(String, String),
3838
Rm(String),
39+
Inspect(String),
3940
List,
4041
}
4142

docs/docs-book/src/using-coffee.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ To list available plugins in a specific remote repository
7474
> ✅ Implemented
7575
7676
```bash
77-
coffee remote <repository_name> --plugins
77+
coffee remote inspect <repository_name>
7878
```
7979

8080
### Install a Plugin

0 commit comments

Comments
 (0)