Skip to content

Commit

Permalink
feat(lib): add support for binary configuration
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
vincenzopalazzo committed Feb 5, 2024
1 parent ee264b2 commit ed48a27
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
13 changes: 10 additions & 3 deletions coffee_github/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@ impl Github {

let conf_file = serde_yaml::from_str::<Conf>(&conf_str)
.map_err(|err| error!("Coffee manifest malformed: {err}"))?;
plugin_name = Some(conf_file.plugin.name.to_string());
let conf_lang = conf_file.plugin.lang.to_owned();

let Some(ref plugin) = conf_file.plugin else {
// FIXME: read the binary information and store it anywhere
break;
};

plugin_name = Some(plugin.name.to_string());
let conf_lang = plugin.lang.to_owned();

match conf_lang.as_str() {
"pypip" => plugin_lang = PluginLang::PyPip,
"pypoetry" => plugin_lang = PluginLang::PyPoetry,
Expand All @@ -117,7 +124,7 @@ impl Github {
}
};

exec_path = Some(format!("{root_path}/{}", conf_file.plugin.main));
exec_path = Some(format!("{root_path}/{}", plugin.main));
conf = Some(conf_file);
break;
}
Expand Down
5 changes: 4 additions & 1 deletion coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ impl Plugin {
pub async fn configure(&mut self, verbose: bool) -> Result<String, CoffeeError> {
log::debug!("install plugin inside from root dir {}", self.root_path);
let exec_path = if let Some(conf) = &self.conf {
if let Some(script) = &conf.plugin.install {
let Some(ref plugin) = conf.plugin else {
return Err(error!("plugin {self} is not a plugin"));
};
if let Some(script) = &plugin.install {
sh!(self.root_path.clone(), script, verbose);
self.exec_path.clone()
} else {
Expand Down
19 changes: 10 additions & 9 deletions coffee_lib/src/plugin_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@
use serde::{Deserialize, Serialize};

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

pub struct Conf {
pub plugin: Plugin,
pub plugin: Option<Plugin>,
pub bin: Option<Binary>,
}

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

pub struct Plugin {
pub name: String,
pub version: String,
pub lang: String,
pub deprecated: Option<()>,
pub deprecated: Option<Deprecaterd>,
pub dependencies: Option<Vec<String>>,
pub install: Option<String>,
pub main: String,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Deprecaterd {
pub reason: String,
}

#[cfg(test)]
mod tests {
#[test]
fn test_remote() {}
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Binary {
pub name: String,
pub deprecated: Option<Deprecaterd>,
pub dependencies: Option<Vec<String>>,
pub install: Option<String>,
}

0 comments on commit ed48a27

Please sign in to comment.