adrift_core 0.0.11

Adrift a web framework for Rust
Documentation
pub mod inspire;
pub mod make_command;
pub mod serve;
pub mod clean;
pub mod queue_work;

use std::collections::HashMap;
use std::fmt::Debug;

use async_trait::async_trait;

pub type Arg = clap::Arg;
pub use clap::arg;

#[async_trait]
pub trait Command {
    fn name(&self) -> &'static str;

    async fn handle(
        &self,
        args: HashMap<String, String>,
    ) -> anyhow::Result<()>;

    fn description(&self) -> &'static str {
        ""
    }

    fn require_rebuild(&self) -> bool {
        false
    }

    fn require_full_rebuild(&self) -> bool {
        false
    }

    fn args(&self) -> Vec<Arg> {
        vec![]
    }
}

impl Debug for dyn Command {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.name())
    }
}

#[derive(Debug)]
pub struct Commands {
    pub items: Vec<Box<dyn Command>>,
}

pub fn get_commands() -> Vec<Box<dyn Command>> {
    vec![
        Box::new(inspire::Inspire),
        Box::new(serve::Serve),
        Box::new(make_command::MakeCommand),
        Box::new(clean::Clean),
        Box::new(queue_work::QueueWork),
    ]
}