Skip to content

Commit 20be671

Browse files
committed
feat: add coffee unlink command
- Add methods in `coffee_core` to enable unlinking coffee configuration from CLN configuration - Update `coffee_cmd` crate to support the new `unlink` command - Add documentation for the new `unlink` command Note: The `clightningrpc-conf` from git is required to use the `rm_subconf()` method. Signed-off-by: Tarek <[email protected]>
1 parent 8a494e1 commit 20be671

File tree

8 files changed

+54
-5
lines changed

8 files changed

+54
-5
lines changed

Cargo.lock

+11-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coffee_cmd/src/cmd.rs

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub enum CoffeeCommand {
3030
/// configuration
3131
#[clap(arg_required_else_help = true)]
3232
Link { cln_conf: String },
33+
/// Unlink coffee from the core lightning configuration
34+
#[clap(arg_required_else_help = true)]
35+
Unlink { cln_conf: String },
3336
/// Install a single by name.
3437
#[clap(arg_required_else_help = true)]
3538
Install {
@@ -100,6 +103,7 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation {
100103
fn from(value: &CoffeeCommand) -> Self {
101104
match value {
102105
CoffeeCommand::Link { cln_conf } => Self::Link(cln_conf.to_owned()),
106+
CoffeeCommand::Unlink { cln_conf } => Self::Unlink(cln_conf.to_owned()),
103107
CoffeeCommand::Install {
104108
plugin,
105109
verbose,

coffee_cmd/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ async fn run(args: CoffeeArgs, mut coffee: CoffeeManager) -> Result<(), CoffeeEr
2121
// and the coffee script
2222
coffee.link(&cln_conf).await?;
2323
}
24+
CoffeeCommand::Unlink { cln_conf } => {
25+
coffee.unlink(&cln_conf).await?;
26+
}
2427
CoffeeCommand::Install {
2528
plugin,
2629
verbose,

coffee_core/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ edition = "2021"
88
tokio = { version = "1.22.0", features = ["full"] }
99
async-trait = "0.1.57"
1010
coffee_lib = { path = "../coffee_lib" }
11-
coffee_github = { path = "../coffee_github" }
11+
coffee_github = { path = "../coffee_github" }
1212
log = "0.4.17"
1313
env_logger = "0.9.3"
14-
coffee_storage = { path = "../coffee_storage" }
14+
coffee_storage = { path = "../coffee_storage" }
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = "1"
17-
clightningrpc-conf = "0.0.3"
17+
clightningrpc-conf = { git = "https://github.com/laanwj/cln4rust" }
1818
clightningrpc-common = "0.3.0-beta.4"
1919
git2 = "^0.18.1"
2020
chrono = { version = "0.4", features = ["std"], default-features = false }

coffee_core/src/coffee.rs

+21
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,20 @@ impl CoffeeManager {
243243
conf.flush()?;
244244
Ok(())
245245
}
246+
247+
/// Unlink coffee from the core lightning configuration file
248+
pub async fn unlink_from_cln(&mut self, cln_dir: &str) -> Result<(), CoffeeError> {
249+
if self.cln_config.is_none() {
250+
return Err(error!("no cln configuration found"));
251+
}
252+
let path_with_network = format!("{cln_dir}/{}/config", self.config.network);
253+
log::info!("teardown coffee in the following cln config {path_with_network}");
254+
let mut conf = self.cln_config.clone().unwrap();
255+
conf.rm_subconf(&self.coffee_cln_config.clone().path)
256+
.map_err(|err| error!("{}", &err.cause))?;
257+
conf.flush()?;
258+
Ok(())
259+
}
246260
}
247261

248262
#[async_trait]
@@ -424,6 +438,13 @@ impl PluginManager for CoffeeManager {
424438
Ok(())
425439
}
426440

441+
async fn unlink(&mut self, cln_dir: &str) -> Result<(), CoffeeError> {
442+
self.unlink_from_cln(cln_dir).await?;
443+
log::info!("cln configuration removed");
444+
self.flush().await?;
445+
Ok(())
446+
}
447+
427448
async fn add_remote(&mut self, name: &str, url: &str) -> Result<(), CoffeeError> {
428449
// FIXME: we should allow some error here like
429450
// for the add remote command the no found error for the `repository`

coffee_core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub use coffee_lib as lib;
99
pub enum CoffeeOperation {
1010
/// Link coffee to the lightning configuration file
1111
Link(String),
12+
/// Unlink coffee from the lightning configuration file
13+
Unlink(String),
1214
/// Install(plugin name, verbose run, dynamic installation)
1315
Install(String, bool, bool),
1416
/// List

coffee_lib/src/plugin_manager.rs

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pub trait PluginManager {
4242
/// Link coffee to CLN configuration file
4343
async fn link(&mut self, cln_conf_path: &str) -> Result<(), CoffeeError>;
4444

45+
/// Unlink coffee from CLN configuration file
46+
async fn unlink(&mut self, cln_conf_path: &str) -> Result<(), CoffeeError>;
47+
4548
/// show the README file of the plugin
4649
async fn show(&mut self, plugin: &str) -> Result<CoffeeShow, CoffeeError>;
4750

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

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ and you can do it with the following command
2121
coffee link /home/alice/.lightning
2222
```
2323

24+
If you want to unlink coffee from Core Lightning configuration at any time, you
25+
can do it with the following command
26+
27+
```bash
28+
coffee unlink /home/alice/.lightning
29+
```
30+
2431
Then you will find an include at the end of the config file at
2532
`/home/alice/.lightning/bitcoin/config`, in case this config file do not exist
2633
Coffee will create it.

0 commit comments

Comments
 (0)