1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pub mod inspire;
pub mod make_command;
pub mod serve;
pub mod clean;

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>>,
}