Skip to content

Commit 8a494e1

Browse files
committed
refactor: rename setup command to link
- Rename `coffee setup` command to `coffee link` - Change function names from `setup_*` to `link_*` (e.g., `setup_with_cln` to `link_with_cln`) - Update command references in `httpd` and `plugin` crates - Modify relevant documentation to reflect the command name change This refactor is to accommodate the addition of a new `unlink` command. Signed-off-by: Tarek <[email protected]>
1 parent ad160b2 commit 8a494e1

File tree

11 files changed

+32
-37
lines changed

11 files changed

+32
-37
lines changed

coffee_cmd/src/cmd.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ pub struct CoffeeArgs {
2626
/// Coffee subcommand of the command line daemon.
2727
#[derive(Debug, Subcommand)]
2828
pub enum CoffeeCommand {
29+
/// Configure coffee with the core lightning
30+
/// configuration
31+
#[clap(arg_required_else_help = true)]
32+
Link { cln_conf: String },
2933
/// Install a single by name.
3034
#[clap(arg_required_else_help = true)]
3135
Install {
@@ -56,10 +60,6 @@ pub enum CoffeeCommand {
5660
#[arg(name = "remote-name", help = "The name of the remote repository")]
5761
name: Option<String>,
5862
},
59-
/// Configure coffee with the core lightning
60-
/// configuration
61-
#[clap(arg_required_else_help = true)]
62-
Setup { cln_conf: String },
6363
/// show the README file of the plugin
6464
#[clap(arg_required_else_help = true)]
6565
Show { plugin: String },
@@ -99,14 +99,14 @@ pub enum RemoteAction {
9999
impl From<&CoffeeCommand> for coffee_core::CoffeeOperation {
100100
fn from(value: &CoffeeCommand) -> Self {
101101
match value {
102+
CoffeeCommand::Link { cln_conf } => Self::Link(cln_conf.to_owned()),
102103
CoffeeCommand::Install {
103104
plugin,
104105
verbose,
105106
dynamic,
106107
} => Self::Install(plugin.to_owned(), *verbose, *dynamic),
107108
CoffeeCommand::Upgrade { repo, verbose } => Self::Upgrade(repo.to_owned(), *verbose),
108109
CoffeeCommand::List {} => Self::List,
109-
CoffeeCommand::Setup { cln_conf } => Self::Setup(cln_conf.to_owned()),
110110
CoffeeCommand::Remote { action, name } => {
111111
if let Some(action) = action {
112112
return Self::Remote(Some(action.into()), name.clone());

coffee_cmd/src/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ use crate::cmd::RemoteAction;
1616

1717
async fn run(args: CoffeeArgs, mut coffee: CoffeeManager) -> Result<(), CoffeeError> {
1818
match args.command {
19+
CoffeeCommand::Link { cln_conf } => {
20+
// FIXME: read the core lightning config
21+
// and the coffee script
22+
coffee.link(&cln_conf).await?;
23+
}
1924
CoffeeCommand::Install {
2025
plugin,
2126
verbose,
@@ -134,11 +139,6 @@ async fn run(args: CoffeeArgs, mut coffee: CoffeeManager) -> Result<(), CoffeeEr
134139
}
135140
}
136141
}
137-
CoffeeCommand::Setup { cln_conf } => {
138-
// FIXME: read the core lightning config
139-
// and the coffee script
140-
coffee.setup(&cln_conf).await?;
141-
}
142142
CoffeeCommand::Show { plugin } => {
143143
let val = coffee.show(&plugin).await?;
144144

coffee_core/src/coffee.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl CoffeeManager {
228228
Ok(())
229229
}
230230

231-
pub async fn setup_with_cln(&mut self, cln_dir: &str) -> Result<(), CoffeeError> {
231+
pub async fn link_with_cln(&mut self, cln_dir: &str) -> Result<(), CoffeeError> {
232232
if self.cln_config.is_some() {
233233
log::warn!("you are overriding the previous set up");
234234
}
@@ -417,8 +417,8 @@ impl PluginManager for CoffeeManager {
417417
Ok(status)
418418
}
419419

420-
async fn setup(&mut self, cln_dir: &str) -> Result<(), CoffeeError> {
421-
self.setup_with_cln(cln_dir).await?;
420+
async fn link(&mut self, cln_dir: &str) -> Result<(), CoffeeError> {
421+
self.link_with_cln(cln_dir).await?;
422422
log::info!("cln configured");
423423
self.flush().await?;
424424
Ok(())

coffee_core/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub use coffee_lib as lib;
77

88
#[derive(Clone, Debug)]
99
pub enum CoffeeOperation {
10+
/// Link coffee to the lightning configuration file
11+
Link(String),
1012
/// Install(plugin name, verbose run, dynamic installation)
1113
Install(String, bool, bool),
1214
/// List
@@ -16,8 +18,6 @@ pub enum CoffeeOperation {
1618
Remove(String),
1719
/// Remote(name repository, url of the repository)
1820
Remote(Option<RemoteAction>, Option<String>),
19-
/// Setup(core lightning root path)
20-
Setup(String),
2121
Show(String),
2222
/// Search(plugin name)
2323
Search(String),

coffee_httpd/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async fn main() -> Result<(), CoffeeError> {
1313
env_logger::init();
1414
let cmd = cmd::HttpdArgs::parse();
1515
let mut coffee = CoffeeManager::new(&cmd).await?;
16-
coffee.setup(&cmd.cln_path).await?;
16+
coffee.link(&cmd.cln_path).await?;
1717

1818
let port = cmd.port.unwrap_or(8080) as u16;
1919
log::info!("Running on port 127.0.0.1:{port}");

coffee_lib/src/plugin_manager.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ pub trait PluginManager {
3939
/// List the plugins available in a remote repository.
4040
async fn get_plugins_in_remote(&self, name: &str) -> Result<CoffeeList, CoffeeError>;
4141

42-
/// set up the core lightning configuration target for the
43-
/// plugin manager.
44-
async fn setup(&mut self, cln_conf_path: &str) -> Result<(), CoffeeError>;
42+
/// Link coffee to CLN configuration file
43+
async fn link(&mut self, cln_conf_path: &str) -> Result<(), CoffeeError>;
4544

4645
/// show the README file of the plugin
4746
async fn show(&mut self, plugin: &str) -> Result<CoffeeShow, CoffeeError>;

coffee_plugin/src/plugin/plugin_mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn on_init(plugin: &mut Plugin<State>) -> Value {
6464
}
6565
let coffee = coffee.unwrap();
6666
plugin.state.set_coffee(coffee);
67-
plugin.state.setup().await
67+
plugin.state.link().await
6868
});
6969

7070
if let Err(err) = result {

coffee_plugin/src/plugin/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ impl State {
4141
self.args.clone().unwrap()
4242
}
4343

44-
pub async fn setup(&self) -> Result<(), CoffeeError> {
44+
pub async fn link(&self) -> Result<(), CoffeeError> {
4545
self.coffee()
4646
.lock()
4747
.unwrap()
48-
.setup(&self.args.clone().unwrap().conf)
48+
.link(&self.args.clone().unwrap().conf)
4949
.await?;
5050
Ok(())
5151
}

docs/docs-book/src/introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ In fact, you can install a Java plugin that supports Coffee in a couple of
3737
commands after you [install it](./install-coffee.md)
3838

3939
```bash
40-
coffee --network testnet setup /home/alice/.lightning
40+
coffee --network testnet link /home/alice/.lightning
4141
coffee --network testnet remote add lightningd https://github.com/lightningd/plugins.git
4242
coffee --network testnet install btcli4j
4343
```

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ By default the Core Lightning home is stored in the `/home/<user>/.lightning`,
1818
and you can do it with the following command
1919

2020
```bash
21-
coffee setup /home/alice/.lightning
21+
coffee link /home/alice/.lightning
2222
```
2323

2424
Then you will find an include at the end of the config file at

tests/src/coffee_integration_tests.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub async fn init_coffee_test_with_cln() -> anyhow::Result<()> {
8181
let lightning_dir = lightning_dir.strip_suffix("/regtest").unwrap();
8282
log::info!("lightning path: {lightning_dir}");
8383

84-
manager.coffee().setup(&lightning_dir).await?;
84+
manager.coffee().link(&lightning_dir).await?;
8585

8686
Ok(())
8787
}
@@ -103,7 +103,7 @@ pub async fn init_coffee_test_add_remote() {
103103
let lightning_dir = lightning_dir.strip_suffix("/regtest").unwrap();
104104
log::info!("lightning path: {lightning_dir}");
105105

106-
manager.coffee().setup(&lightning_dir).await.unwrap();
106+
manager.coffee().link(&lightning_dir).await.unwrap();
107107

108108
manager
109109
.coffee()
@@ -135,7 +135,7 @@ pub async fn test_add_remove_plugins() {
135135
let lightning_dir = lightning_dir.strip_suffix("/regtest").unwrap();
136136
log::info!("lightning path: {lightning_dir}");
137137

138-
manager.coffee().setup(&lightning_dir).await.unwrap();
138+
manager.coffee().link(&lightning_dir).await.unwrap();
139139
// Add lightningd remote repository
140140
let repo_name = "lightningd";
141141
let repo_url = "https://github.com/lightningd/plugins.git";
@@ -254,7 +254,7 @@ pub async fn test_errors_and_show() {
254254
let lightning_dir = lightning_dir.strip_suffix("/regtest").unwrap();
255255
log::info!("lightning path: {lightning_dir}");
256256

257-
manager.coffee().setup(&lightning_dir).await.unwrap();
257+
manager.coffee().link(&lightning_dir).await.unwrap();
258258
// Add lightningd remote repository
259259
let repo_name = "lightningd";
260260
let repo_url = "https://github.com/lightningd/plugins.git";
@@ -341,7 +341,7 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> {
341341
network: "regtest".to_string(),
342342
};
343343
let mut manager = CoffeeTesting::tmp_with_args(&args, dir.clone()).await?;
344-
let result = manager.coffee().setup(&lightning_regtest_dir).await;
344+
let result = manager.coffee().link(&lightning_regtest_dir).await;
345345
assert!(result.is_ok(), "{:?}", result);
346346
// Add lightningd remote repository
347347
manager
@@ -378,11 +378,7 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> {
378378
let mut manager = CoffeeTesting::tmp_with_args(&new_args, dir.clone()).await?;
379379
let new_root_path = manager.root_path().to_owned();
380380
assert_eq!(dir.path(), new_root_path.path());
381-
manager
382-
.coffee()
383-
.setup(&lightning_testnet_dir)
384-
.await
385-
.unwrap();
381+
manager.coffee().link(&lightning_testnet_dir).await.unwrap();
386382

387383
let result = manager
388384
.coffee()
@@ -416,7 +412,7 @@ pub async fn test_double_slash() {
416412
let lightning_dir = cln.rpc().getinfo().unwrap().ligthning_dir;
417413
let lightning_dir = lightning_dir.strip_suffix("/regtest").unwrap();
418414
log::info!("lightning path: {lightning_dir}");
419-
manager.coffee().setup(&lightning_dir).await.unwrap();
415+
manager.coffee().link(&lightning_dir).await.unwrap();
420416

421417
// Add lightningd remote repository
422418
let repo_name = "lightningd";
@@ -481,7 +477,7 @@ pub async fn test_plugin_installation_path() {
481477
let lightning_dir = lightning_dir.strip_suffix("/regtest").unwrap();
482478
log::info!("lightning path: {lightning_dir}");
483479

484-
manager.coffee().setup(&lightning_dir).await.unwrap();
480+
manager.coffee().link(&lightning_dir).await.unwrap();
485481

486482
// Add lightningd remote repository
487483
manager
@@ -589,7 +585,7 @@ pub async fn test_nurse_repository_missing_on_disk() {
589585
let lightning_dir = lightning_dir.strip_suffix("/regtest").unwrap();
590586
log::info!("lightning path: {lightning_dir}");
591587

592-
manager.coffee().setup(&lightning_dir).await.unwrap();
588+
manager.coffee().link(&lightning_dir).await.unwrap();
593589

594590
// Construct the root path
595591
let root_path = manager

0 commit comments

Comments
 (0)