Skip to content

Commit

Permalink
feat: support important plugins
Browse files Browse the repository at this point in the history
added a new manifest field to mark plugin as important
only install as static and important

part of #245
  • Loading branch information
daywalker90 committed Mar 1, 2024
1 parent e4b1ab7 commit 8075ac8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
21 changes: 19 additions & 2 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ impl PluginManager for CoffeeManager {
if let Some(mut plugin) = repo.get_plugin_by_name(plugin) {
log::trace!("{:?}", plugin);

if try_dynamic && plugin.important() {
return Err(error!(
"plugin is important, can't be dynamically installed"
));
}

// old_root_path is the path where the plugin is cloned and currently stored
// eg. ~/.coffee/repositories/<repo_name>/<plugin_name>
let old_root_path = plugin.root_path.clone();
Expand All @@ -297,6 +303,12 @@ impl PluginManager for CoffeeManager {
);
let old_exec_path = plugin.exec_path.clone();

let plugin_conf_key = if plugin.important() {
"important-plugin"
} else {
"plugin"
};

match old_exec_path.strip_prefix(&old_root_path) {
Some(relative_path) => {
let new_exec_path = format!("{}{}", new_root_path, relative_path);
Expand All @@ -312,7 +324,7 @@ impl PluginManager for CoffeeManager {
self.config.plugins.push(plugin);
log::debug!("path coffee conf: {}", self.coffee_cln_config.path);
self.coffee_cln_config
.add_conf("plugin", &path.to_owned())
.add_conf(plugin_conf_key, &path.to_owned())
.map_err(|err| error!("{}", err.cause))?;
log::debug!("coffee conf updated: {}", self.coffee_cln_config);
self.flush().await?;
Expand Down Expand Up @@ -348,9 +360,14 @@ impl PluginManager for CoffeeManager {
log::debug!("runnable plugin path: {exec_path}");
plugins.remove(index);
log::debug!("coffee cln config: {}", self.coffee_cln_config);
let plugin_conf_key = if plugin.important() {
"important-plugin"
} else {
"plugin"
};
let remove_config = self
.coffee_cln_config
.rm_conf("plugin", Some(&exec_path.to_owned()));
.rm_conf(plugin_conf_key, Some(&exec_path.to_owned()));
if let Err(err) = remove_config {
// if this is true, we are probably a dynamic plugin:
if err.cause.contains("field with `plugin` not present") {
Expand Down
12 changes: 12 additions & 0 deletions coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ impl Plugin {
pub fn tipping_info(&self) -> Option<Tipping> {
self.conf.as_ref().and_then(|conf| conf.tipping.clone())
}

pub fn important(&self) -> bool {
if let Some(config) = &self.conf {
if let Some(important) = config.plugin.important {
important
} else {
false
}
} else {
false
}
}
}

impl fmt::Display for Plugin {
Expand Down
1 change: 1 addition & 0 deletions coffee_lib/src/plugin_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Plugin {
pub dependencies: Option<Vec<String>>,
pub install: Option<String>,
pub main: String,
pub important: Option<bool>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions docs/docs-book/src/support-coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Where it is possible to specify the following options:
- `lang`: the language of the plugin, used to try to install a plugin when the `install` script is not specified;
- `install`: a custom install script used by Coffee to compile the plugin;
- `main`: the binary or runnable file that core lightning needs to run.
- `important`: bool flag for plugins that must be run as important-plugin

In the future, the coffee will be also able to install `binary` other than a `plugin`, so coffee will be installed with coffee
itself. With some craziness will be also possible to manage core lightning itself.
Expand Down

0 comments on commit 8075ac8

Please sign in to comment.