Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): add support for binary installation #101

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions coffee_core/src/coffee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 19 additions & 4 deletions coffee_github/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -101,8 +101,18 @@ 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().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,
Expand All @@ -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;
}
Expand Down Expand Up @@ -232,6 +245,8 @@ impl Repository for Github {
}

async fn upgrade(&mut self, plugins: &Vec<Plugin>) -> Result<CoffeeUpgrade, CoffeeError> {
// 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<String> = vec![];
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
21 changes: 8 additions & 13 deletions coffee_lib/src/plugin_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
use serde::{Deserialize, Serialize};

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

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

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

pub struct Plugin {
pub name: String,
pub version: String,
pub lang: String,
pub deprecated: Option<()>,
pub lang: Option<String>,
/// Is the plugin a binary?
pub binary: Option<bool>,
pub deprecated: Option<Deprecaterd>,
pub dependencies: Option<Vec<String>>,
pub install: Option<String>,
pub main: String,
pub main: Option<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() {}
}
Loading