by_loco/tests_cfg/
task.rs

1use crate::prelude::*;
2
3#[derive(Debug)]
4pub struct Foo;
5
6#[async_trait]
7impl Task for Foo {
8    fn task(&self) -> TaskInfo {
9        TaskInfo {
10            name: "foo".to_string(),
11            detail: "run foo task".to_string(),
12        }
13    }
14    async fn run(&self, _app_context: &AppContext, _vars: &task::Vars) -> Result<()> {
15        println!("Foo task executed!!!");
16        Ok(())
17    }
18}
19
20#[derive(Debug)]
21pub struct ParseArgs;
22
23#[async_trait]
24impl Task for ParseArgs {
25    fn task(&self) -> TaskInfo {
26        TaskInfo {
27            name: "parse_args".to_string(),
28            detail: "Validate the paring args".to_string(),
29        }
30    }
31    async fn run(&self, _app_context: &AppContext, vars: &task::Vars) -> Result<()> {
32        let refresh = vars.cli_arg("test").is_ok_and(|test| test == "true");
33
34        let app = vars
35            .cli_arg("app")
36            .map(std::string::ToString::to_string)
37            .unwrap_or_default();
38
39        if refresh && app == "loco" {
40            Ok(())
41        } else {
42            Err(Error::string("invalid args"))
43        }
44    }
45}