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 coffee-tools#245
  • Loading branch information
daywalker90 committed Feb 27, 2024
1 parent e14d7d5 commit 62c8fa0
Show file tree
Hide file tree
Showing 4 changed files with 34 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 @@ -253,6 +253,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 @@ -279,6 +285,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 @@ -294,7 +306,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 @@ -328,8 +340,13 @@ 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"
};
self.coffee_cln_config
.rm_conf("plugin", Some(&exec_path.to_owned()))
.rm_conf(plugin_conf_key, Some(&exec_path.to_owned()))
.map_err(|err| error!("{}", &err.cause))?;
self.flush().await?;
self.update_conf().await?;
Expand Down
13 changes: 13 additions & 0 deletions coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ impl Plugin {
pub fn tipping_info(&self) -> Option<Tipping> {
self.conf.as_ref().and_then(|conf| conf.tipping.clone())
}

pub fn important(&self) -> bool {
let config = if let Some(conf) = &self.conf {
conf
} else {
return false;
};
if let Some(important) = config.plugin.important {
important
} 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 62c8fa0

Please sign in to comment.