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
use super::Input;

#[derive(Clone, Debug,Default)]
pub struct TaskInfo {
    pub name: String,
    pub help: String,
    pub flags: Vec<(String, String, String)>, //参数名称 默认 帮助
}

impl TaskInfo{
    pub fn new<S:ToString,H:ToString>(name:S,help:H)->Self{
        Self{
            name:name.to_string(),
            help:help.to_string(),
            flags:vec![],
        }
    }
    pub fn register_arg<A:ToString,D:ToString,H:ToString>(mut self,arg:A,default:D,help:H)->Self{
        self.flags.push((arg.to_string(),default.to_string(),help.to_string()));self
    }
}

#[async_trait::async_trait]
pub trait Task : Send + Sync {
    fn info(&self)->TaskInfo;
    async fn run(&self,input:Input)->anyhow::Result<()>;
    async fn exit(&self,_input:Input)->anyhow::Result<()>{
        Ok(())
    }
}