adrift_core/
commands.rs

1pub mod inspire;
2pub mod make_command;
3pub mod serve;
4pub mod clean;
5pub mod queue_work;
6
7use std::collections::HashMap;
8use std::fmt::Debug;
9
10use async_trait::async_trait;
11
12pub type Arg = clap::Arg;
13pub use clap::arg;
14
15#[async_trait]
16pub trait Command {
17    fn name(&self) -> &'static str;
18
19    async fn handle(
20        &self,
21        args: HashMap<String, String>,
22    ) -> anyhow::Result<()>;
23
24    fn description(&self) -> &'static str {
25        ""
26    }
27
28    fn require_rebuild(&self) -> bool {
29        false
30    }
31
32    fn require_full_rebuild(&self) -> bool {
33        false
34    }
35
36    fn args(&self) -> Vec<Arg> {
37        vec![]
38    }
39}
40
41impl Debug for dyn Command {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        f.write_str(self.name())
44    }
45}
46
47#[derive(Debug)]
48pub struct Commands {
49    pub items: Vec<Box<dyn Command>>,
50}
51
52pub fn get_commands() -> Vec<Box<dyn Command>> {
53    vec![
54        Box::new(inspire::Inspire),
55        Box::new(serve::Serve),
56        Box::new(make_command::MakeCommand),
57        Box::new(clean::Clean),
58        Box::new(queue_work::QueueWork),
59    ]
60}