use log::warn;
use shrs_core::shell::{Context, Runtime, Shell};
use crate::ShellConfig;
#[derive(Debug)]
pub struct PluginMeta {
pub name: String,
pub description: String,
}
#[derive(Debug)]
pub enum FailMode {
Warn,
Abort,
}
impl Default for PluginMeta {
fn default() -> Self {
Self {
name: String::from("unnamed plugin"),
description: String::from("a plugin for shrs"),
}
}
}
pub trait Plugin {
fn init(&self, shell: &mut ShellConfig) -> anyhow::Result<()>;
fn post_init(&self, sh: &Shell, ctx: &mut Context, rt: &mut Runtime) -> anyhow::Result<()> {
Ok(())
}
fn meta(&self) -> PluginMeta {
warn!("Using default plugin metadata. Please specify this information for your plugin by implementing Plugin::meta()");
PluginMeta::default()
}
fn fail_mode(&self) -> FailMode {
FailMode::Abort
}
}
pub trait ShellPlugin {
fn with_plugin(&mut self, plugin: impl Plugin);
}