Skip to content

Commit f4208f9

Browse files
daywalker90vincenzopalazzo
authored andcommitted
feat: support important plugins
added a new manifest field to mark plugin as important only install as static and important part of #245
1 parent e4b1ab7 commit f4208f9

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

coffee_core/src/coffee.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ impl PluginManager for CoffeeManager {
271271
if let Some(mut plugin) = repo.get_plugin_by_name(plugin) {
272272
log::trace!("{:?}", plugin);
273273

274+
if try_dynamic && plugin.important() {
275+
return Err(error!(
276+
"plugin is important, can't be dynamically installed"
277+
));
278+
}
279+
274280
// old_root_path is the path where the plugin is cloned and currently stored
275281
// eg. ~/.coffee/repositories/<repo_name>/<plugin_name>
276282
let old_root_path = plugin.root_path.clone();
@@ -297,6 +303,12 @@ impl PluginManager for CoffeeManager {
297303
);
298304
let old_exec_path = plugin.exec_path.clone();
299305

306+
let plugin_conf_key = if plugin.important() {
307+
"important-plugin"
308+
} else {
309+
"plugin"
310+
};
311+
300312
match old_exec_path.strip_prefix(&old_root_path) {
301313
Some(relative_path) => {
302314
let new_exec_path = format!("{}{}", new_root_path, relative_path);
@@ -312,7 +324,7 @@ impl PluginManager for CoffeeManager {
312324
self.config.plugins.push(plugin);
313325
log::debug!("path coffee conf: {}", self.coffee_cln_config.path);
314326
self.coffee_cln_config
315-
.add_conf("plugin", &path.to_owned())
327+
.add_conf(plugin_conf_key, &path.to_owned())
316328
.map_err(|err| error!("{}", err.cause))?;
317329
log::debug!("coffee conf updated: {}", self.coffee_cln_config);
318330
self.flush().await?;
@@ -348,9 +360,14 @@ impl PluginManager for CoffeeManager {
348360
log::debug!("runnable plugin path: {exec_path}");
349361
plugins.remove(index);
350362
log::debug!("coffee cln config: {}", self.coffee_cln_config);
363+
let plugin_conf_key = if plugin.important() {
364+
"important-plugin"
365+
} else {
366+
"plugin"
367+
};
351368
let remove_config = self
352369
.coffee_cln_config
353-
.rm_conf("plugin", Some(&exec_path.to_owned()));
370+
.rm_conf(plugin_conf_key, Some(&exec_path.to_owned()));
354371
if let Err(err) = remove_config {
355372
// if this is true, we are probably a dynamic plugin:
356373
if err.cause.contains("field with `plugin` not present") {

coffee_lib/src/plugin.rs

+12
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ impl Plugin {
165165
pub fn tipping_info(&self) -> Option<Tipping> {
166166
self.conf.as_ref().and_then(|conf| conf.tipping.clone())
167167
}
168+
169+
pub fn important(&self) -> bool {
170+
if let Some(config) = &self.conf {
171+
if let Some(important) = config.plugin.important {
172+
important
173+
} else {
174+
false
175+
}
176+
} else {
177+
false
178+
}
179+
}
168180
}
169181

170182
impl fmt::Display for Plugin {

coffee_lib/src/plugin_conf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct Plugin {
1616
pub dependencies: Option<Vec<String>>,
1717
pub install: Option<String>,
1818
pub main: String,
19+
pub important: Option<bool>,
1920
}
2021

2122
#[derive(Debug, PartialEq, Serialize, Deserialize)]

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

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Where it is possible to specify the following options:
3535
- `lang`: the language of the plugin, used to try to install a plugin when the `install` script is not specified;
3636
- `install`: a custom install script used by Coffee to compile the plugin;
3737
- `main`: the binary or runnable file that core lightning needs to run.
38+
- `important`: bool flag for plugins that must be run as important-plugin
3839

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

0 commit comments

Comments
 (0)