diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index 3761e9f1..add38f0a 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -287,6 +287,7 @@ impl PluginManager for CoffeeManager { plugin.exec_path = new_exec_path; log::debug!("plugin: {:?}", plugin); + // TODO: install the binary and return early let path = plugin.configure(verbose).await?; log::debug!("runnable plugin path {path}"); if !try_dynamic { diff --git a/coffee_github/src/repository.rs b/coffee_github/src/repository.rs index 97728f1f..12a5dcc2 100644 --- a/coffee_github/src/repository.rs +++ b/coffee_github/src/repository.rs @@ -2,7 +2,6 @@ use std::any::Any; use async_trait::async_trait; use chrono::{TimeZone, Utc}; -use coffee_lib::types::response::CoffeeUpgrade; use git2; use log::debug; use tokio::fs::File; @@ -16,6 +15,7 @@ use coffee_lib::plugin::Plugin; use coffee_lib::plugin::PluginLang; use coffee_lib::plugin_conf::Conf; use coffee_lib::repository::Repository; +use coffee_lib::types::response::CoffeeUpgrade; use coffee_lib::url::URL; use coffee_lib::utils::get_plugin_info_from_path; use coffee_storage::model::repository::Kind; @@ -101,8 +101,18 @@ impl Github { let conf_file = serde_yaml::from_str::(&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().ok_or(error!( + "Coffee manifest should contain the `lang` field for plugins" + ))?; + + // SAFETY: it is sage to unwrao match conf_lang.as_str() { "pypip" => plugin_lang = PluginLang::PyPip, "pypoetry" => plugin_lang = PluginLang::PyPoetry, @@ -117,7 +127,10 @@ impl Github { } }; - exec_path = Some(format!("{root_path}/{}", conf_file.plugin.main)); + let main = plugin.main.clone().ok_or(error!( + "Coffee manifest should contain the `main` field for plugins" + ))?; + exec_path = Some(format!("{root_path}/{}", main)); conf = Some(conf_file); break; } @@ -232,6 +245,8 @@ impl Repository for Github { } async fn upgrade(&mut self, plugins: &Vec) -> Result { + // TODO: upgrade a binary + // get the list of the plugins installed from this repository // TODO: add a field of installed plugins in the repository struct instead let mut plugins_effected: Vec = vec![]; diff --git a/coffee_lib/src/plugin.rs b/coffee_lib/src/plugin.rs index a8f2f406..13657a94 100644 --- a/coffee_lib/src/plugin.rs +++ b/coffee_lib/src/plugin.rs @@ -132,7 +132,10 @@ impl Plugin { pub async fn configure(&mut self, verbose: bool) -> Result { 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 { diff --git a/coffee_lib/src/plugin_conf.rs b/coffee_lib/src/plugin_conf.rs index 3cb14969..5c795b00 100644 --- a/coffee_lib/src/plugin_conf.rs +++ b/coffee_lib/src/plugin_conf.rs @@ -2,30 +2,25 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] - pub struct Conf { - pub plugin: Plugin, + pub plugin: Option, + pub bin: Option, } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] - pub struct Plugin { pub name: String, pub version: String, - pub lang: String, - pub deprecated: Option<()>, + pub lang: Option, + /// Is the plugin a binary? + pub binary: Option, + pub deprecated: Option, pub dependencies: Option>, pub install: Option, - pub main: String, + pub main: Option, } -#[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() {} -}