Skip to content

Commit 62c8fa0

Browse files
committed
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 e14d7d5 commit 62c8fa0

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

coffee_core/src/coffee.rs

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

256+
if try_dynamic && plugin.important() {
257+
return Err(error!(
258+
"plugin is important, can't be dynamically installed"
259+
));
260+
}
261+
256262
// old_root_path is the path where the plugin is cloned and currently stored
257263
// eg. ~/.coffee/repositories/<repo_name>/<plugin_name>
258264
let old_root_path = plugin.root_path.clone();
@@ -279,6 +285,12 @@ impl PluginManager for CoffeeManager {
279285
);
280286
let old_exec_path = plugin.exec_path.clone();
281287

288+
let plugin_conf_key = if plugin.important() {
289+
"important-plugin"
290+
} else {
291+
"plugin"
292+
};
293+
282294
match old_exec_path.strip_prefix(&old_root_path) {
283295
Some(relative_path) => {
284296
let new_exec_path = format!("{}{}", new_root_path, relative_path);
@@ -294,7 +306,7 @@ impl PluginManager for CoffeeManager {
294306
self.config.plugins.push(plugin);
295307
log::debug!("path coffee conf: {}", self.coffee_cln_config.path);
296308
self.coffee_cln_config
297-
.add_conf("plugin", &path.to_owned())
309+
.add_conf(plugin_conf_key, &path.to_owned())
298310
.map_err(|err| error!("{}", err.cause))?;
299311
log::debug!("coffee conf updated: {}", self.coffee_cln_config);
300312
self.flush().await?;
@@ -328,8 +340,13 @@ impl PluginManager for CoffeeManager {
328340
log::debug!("runnable plugin path: {exec_path}");
329341
plugins.remove(index);
330342
log::debug!("coffee cln config: {}", self.coffee_cln_config);
343+
let plugin_conf_key = if plugin.important() {
344+
"important-plugin"
345+
} else {
346+
"plugin"
347+
};
331348
self.coffee_cln_config
332-
.rm_conf("plugin", Some(&exec_path.to_owned()))
349+
.rm_conf(plugin_conf_key, Some(&exec_path.to_owned()))
333350
.map_err(|err| error!("{}", &err.cause))?;
334351
self.flush().await?;
335352
self.update_conf().await?;

coffee_lib/src/plugin.rs

+13
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ 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+
let config = if let Some(conf) = &self.conf {
171+
conf
172+
} else {
173+
return false;
174+
};
175+
if let Some(important) = config.plugin.important {
176+
important
177+
} else {
178+
false
179+
}
180+
}
168181
}
169182

170183
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)