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 Apr 15, 2023
1 parent fc49bc2 commit 297b67e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
10 changes: 8 additions & 2 deletions coffee_github/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,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 Some(ref plugin) = conf_file.plugin else {
// FIXME: read the binary information and store it anywhere
break;
};

plugin_name = Some(plugin.name.to_string());
path_to_plugin = Some(root_path.to_owned());
let conf_lang = (&conf_file.plugin.lang).to_owned();

let conf_lang = (&plugin.lang).to_owned();
match conf_lang.as_str() {
"pypip" => plugin_lang = PluginLang::PyPip,
"pypoetry" => plugin_lang = PluginLang::PyPoetry,
Expand Down
7 changes: 5 additions & 2 deletions coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ impl Plugin {
/// In case of success return the path of the executable.
pub async fn configure(&mut self, verbose: bool) -> Result<String, CoffeeError> {
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);
format!("{}/{}", self.path, conf.plugin.main)
format!("{}/{}", self.path, plugin.main)
} else {
self.lang
.default_install(&self.path, &self.name, verbose)
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 297b67e

Please sign in to comment.