pub mod crates;
pub mod http;
pub mod pypi;
pub mod rubygems;
use crate::{
SysexitsError::{self},
registry,
};
use asimov_env::{
env::Env,
envs::{PythonEnv, RubyEnv},
};
use derive_more::Display;
#[derive(Clone, Debug)]
pub struct ModuleMetadata {
pub name: String,
pub version: String,
pub r#type: ModuleType,
pub url: String,
}
impl ModuleMetadata {
pub fn is_installed(&self) -> std::io::Result<bool> {
match self.r#type {
ModuleType::Rust => {
let command_name = format!("{}-module", self.name); Ok(clientele::SubcommandsProvider::find("asimov-", &command_name).is_some())
},
ModuleType::Ruby => RubyEnv::default().is_module_installed(&self.name),
ModuleType::Python => PythonEnv::default().is_module_installed(&self.name),
}
}
}
#[derive(Clone, Display, Debug)]
pub enum ModuleType {
#[display("rust")]
Rust,
#[display("ruby")]
Ruby,
#[display("python")]
Python,
}
impl ModuleType {
pub fn origin(&self) -> &'static str {
use ModuleType::*;
match self {
Rust => "Cargo",
Ruby => "RubyGems",
Python => "PyPI",
}
}
}
pub fn is_enabled(_module_name: &str) -> bool {
true }
pub async fn fetch_module(module_name: &str) -> Option<ModuleMetadata> {
let modules = registry::fetch_modules().await.ok()?;
let module = modules.into_iter().find(|m| m.name == module_name);
module
}
pub async fn fetch_modules() -> Result<Vec<ModuleMetadata>, SysexitsError> {
return Ok(Vec::new());
}