Skip to content

Commit 83b3459

Browse files
feat(lib): add support for binary configuration
The tool for core lightning are not all plugin, but they can be just binary like the coffee one. So, this will start to support inside the configuration, the possibility to support binaries installation and tracking. So, a repository can have also custom binaries, like coffee or core lightning itself. Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent ee264b2 commit 83b3459

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

coffee_core/src/coffee.rs

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ impl PluginManager for CoffeeManager {
287287
plugin.exec_path = new_exec_path;
288288

289289
log::debug!("plugin: {:?}", plugin);
290+
// TODO: install the binary and return early
290291
let path = plugin.configure(verbose).await?;
291292
log::debug!("runnable plugin path {path}");
292293
if !try_dynamic {

coffee_github/src/repository.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::any::Any;
22

33
use async_trait::async_trait;
44
use chrono::{TimeZone, Utc};
5-
use coffee_lib::types::response::CoffeeUpgrade;
65
use git2;
76
use log::debug;
87
use tokio::fs::File;
@@ -16,6 +15,7 @@ use coffee_lib::plugin::Plugin;
1615
use coffee_lib::plugin::PluginLang;
1716
use coffee_lib::plugin_conf::Conf;
1817
use coffee_lib::repository::Repository;
18+
use coffee_lib::types::response::CoffeeUpgrade;
1919
use coffee_lib::url::URL;
2020
use coffee_lib::utils::get_plugin_info_from_path;
2121
use coffee_storage::model::repository::Kind;
@@ -101,8 +101,18 @@ impl Github {
101101

102102
let conf_file = serde_yaml::from_str::<Conf>(&conf_str)
103103
.map_err(|err| error!("Coffee manifest malformed: {err}"))?;
104-
plugin_name = Some(conf_file.plugin.name.to_string());
105-
let conf_lang = conf_file.plugin.lang.to_owned();
104+
105+
let Some(ref plugin) = conf_file.plugin else {
106+
// FIXME: read the binary information and store it anywhere
107+
break;
108+
};
109+
110+
plugin_name = Some(plugin.name.to_string());
111+
let conf_lang = plugin.lang.to_owned().ok_or(error!(
112+
"Coffee manifest should contain the `lang` field for plugins"
113+
))?;
114+
115+
// SAFETY: it is sage to unwrao
106116
match conf_lang.as_str() {
107117
"pypip" => plugin_lang = PluginLang::PyPip,
108118
"pypoetry" => plugin_lang = PluginLang::PyPoetry,
@@ -117,7 +127,10 @@ impl Github {
117127
}
118128
};
119129

120-
exec_path = Some(format!("{root_path}/{}", conf_file.plugin.main));
130+
let main = plugin.main.clone().ok_or(error!(
131+
"Coffee manifest should contain the `main` field for plugins"
132+
))?;
133+
exec_path = Some(format!("{root_path}/{}", main));
121134
conf = Some(conf_file);
122135
break;
123136
}
@@ -232,6 +245,8 @@ impl Repository for Github {
232245
}
233246

234247
async fn upgrade(&mut self, plugins: &Vec<Plugin>) -> Result<CoffeeUpgrade, CoffeeError> {
248+
// TODO: upgrade a binary
249+
235250
// get the list of the plugins installed from this repository
236251
// TODO: add a field of installed plugins in the repository struct instead
237252
let mut plugins_effected: Vec<String> = vec![];

coffee_lib/src/plugin.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ impl Plugin {
132132
pub async fn configure(&mut self, verbose: bool) -> Result<String, CoffeeError> {
133133
log::debug!("install plugin inside from root dir {}", self.root_path);
134134
let exec_path = if let Some(conf) = &self.conf {
135-
if let Some(script) = &conf.plugin.install {
135+
let Some(ref plugin) = conf.plugin else {
136+
return Err(error!("plugin {self} is not a plugin"));
137+
};
138+
if let Some(script) = &plugin.install {
136139
sh!(self.root_path.clone(), script, verbose);
137140
self.exec_path.clone()
138141
} else {

coffee_lib/src/plugin_conf.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,25 @@
22
use serde::{Deserialize, Serialize};
33

44
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
5-
65
pub struct Conf {
7-
pub plugin: Plugin,
6+
pub plugin: Option<Plugin>,
7+
pub bin: Option<Plugin>,
88
}
99

1010
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
11-
1211
pub struct Plugin {
1312
pub name: String,
1413
pub version: String,
15-
pub lang: String,
16-
pub deprecated: Option<()>,
14+
pub lang: Option<String>,
15+
/// Is the plugin a binary?
16+
pub binary: Option<bool>,
17+
pub deprecated: Option<Deprecaterd>,
1718
pub dependencies: Option<Vec<String>>,
1819
pub install: Option<String>,
19-
pub main: String,
20+
pub main: Option<String>,
2021
}
2122

22-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
23+
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
2324
pub struct Deprecaterd {
2425
pub reason: String,
2526
}
26-
27-
#[cfg(test)]
28-
mod tests {
29-
#[test]
30-
fn test_remote() {}
31-
}

0 commit comments

Comments
 (0)