Skip to content

Commit

Permalink
feat: add coffee unlink command
Browse files Browse the repository at this point in the history
- 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 <tareknaser360@gmail.com>
  • Loading branch information
tareknaser committed May 29, 2024
1 parent 8a494e1 commit 20be671
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 5 deletions.
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions coffee_cmd/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub enum CoffeeCommand {
/// configuration
#[clap(arg_required_else_help = true)]
Link { cln_conf: String },
/// Unlink coffee from the core lightning configuration
#[clap(arg_required_else_help = true)]
Unlink { cln_conf: String },
/// Install a single by name.
#[clap(arg_required_else_help = true)]
Install {
Expand Down Expand Up @@ -100,6 +103,7 @@ impl From<&CoffeeCommand> for coffee_core::CoffeeOperation {
fn from(value: &CoffeeCommand) -> Self {
match value {
CoffeeCommand::Link { cln_conf } => Self::Link(cln_conf.to_owned()),
CoffeeCommand::Unlink { cln_conf } => Self::Unlink(cln_conf.to_owned()),
CoffeeCommand::Install {
plugin,
verbose,
Expand Down
3 changes: 3 additions & 0 deletions coffee_cmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ async fn run(args: CoffeeArgs, mut coffee: CoffeeManager) -> Result<(), CoffeeEr
// and the coffee script
coffee.link(&cln_conf).await?;
}
CoffeeCommand::Unlink { cln_conf } => {
coffee.unlink(&cln_conf).await?;
}
CoffeeCommand::Install {
plugin,
verbose,
Expand Down
6 changes: 3 additions & 3 deletions coffee_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ edition = "2021"
tokio = { version = "1.22.0", features = ["full"] }
async-trait = "0.1.57"
coffee_lib = { path = "../coffee_lib" }
coffee_github = { path = "../coffee_github" }
coffee_github = { path = "../coffee_github" }
log = "0.4.17"
env_logger = "0.9.3"
coffee_storage = { path = "../coffee_storage" }
coffee_storage = { path = "../coffee_storage" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
clightningrpc-conf = "0.0.3"
clightningrpc-conf = { git = "https://github.com/laanwj/cln4rust" }
clightningrpc-common = "0.3.0-beta.4"
git2 = "^0.18.1"
chrono = { version = "0.4", features = ["std"], default-features = false }
21 changes: 21 additions & 0 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ impl CoffeeManager {
conf.flush()?;
Ok(())
}

/// Unlink coffee from the core lightning configuration file
pub async fn unlink_from_cln(&mut self, cln_dir: &str) -> Result<(), CoffeeError> {
if self.cln_config.is_none() {
return Err(error!("no cln configuration found"));
}
let path_with_network = format!("{cln_dir}/{}/config", self.config.network);
log::info!("teardown coffee in the following cln config {path_with_network}");
let mut conf = self.cln_config.clone().unwrap();
conf.rm_subconf(&self.coffee_cln_config.clone().path)
.map_err(|err| error!("{}", &err.cause))?;
conf.flush()?;
Ok(())
}
}

#[async_trait]
Expand Down Expand Up @@ -424,6 +438,13 @@ impl PluginManager for CoffeeManager {
Ok(())
}

async fn unlink(&mut self, cln_dir: &str) -> Result<(), CoffeeError> {
self.unlink_from_cln(cln_dir).await?;
log::info!("cln configuration removed");
self.flush().await?;
Ok(())
}

async fn add_remote(&mut self, name: &str, url: &str) -> Result<(), CoffeeError> {
// FIXME: we should allow some error here like
// for the add remote command the no found error for the `repository`
Expand Down
2 changes: 2 additions & 0 deletions coffee_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub use coffee_lib as lib;
pub enum CoffeeOperation {
/// Link coffee to the lightning configuration file
Link(String),
/// Unlink coffee from the lightning configuration file
Unlink(String),
/// Install(plugin name, verbose run, dynamic installation)
Install(String, bool, bool),
/// List
Expand Down
3 changes: 3 additions & 0 deletions coffee_lib/src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub trait PluginManager {
/// Link coffee to CLN configuration file
async fn link(&mut self, cln_conf_path: &str) -> Result<(), CoffeeError>;

/// Unlink coffee from CLN configuration file
async fn unlink(&mut self, cln_conf_path: &str) -> Result<(), CoffeeError>;

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

Expand Down
7 changes: 7 additions & 0 deletions docs/docs-book/src/using-coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ and you can do it with the following command
coffee link /home/alice/.lightning
```

If you want to unlink coffee from Core Lightning configuration at any time, you
can do it with the following command

```bash
coffee unlink /home/alice/.lightning
```

Then you will find an include at the end of the config file at
`/home/alice/.lightning/bitcoin/config`, in case this config file do not exist
Coffee will create it.
Expand Down

0 comments on commit 20be671

Please sign in to comment.