mk_lib/schema/
use_cargo.rs

1use hashbrown::HashMap;
2use serde::Deserialize;
3
4use super::Task;
5
6#[derive(Debug, Deserialize)]
7pub struct UseCargoArgs {
8  /// The working directory to run the command in
9  #[serde(default)]
10  pub work_dir: Option<String>,
11}
12
13#[derive(Debug, Deserialize)]
14#[serde(untagged)]
15pub enum UseCargo {
16  Bool(bool),
17  UseCargo(Box<UseCargoArgs>),
18}
19
20impl UseCargo {
21  pub fn capture(&self) -> anyhow::Result<HashMap<String, Task>> {
22    match self {
23      UseCargo::Bool(true) => self.capture_tasks(),
24      UseCargo::UseCargo(args) => args.capture_tasks(),
25      _ => Ok(HashMap::new()),
26    }
27  }
28
29  fn capture_tasks(&self) -> anyhow::Result<HashMap<String, Task>> {
30    UseCargoArgs { work_dir: None }.capture_tasks()
31  }
32}
33
34impl UseCargoArgs {
35  pub fn capture_tasks(&self) -> anyhow::Result<HashMap<String, Task>> {
36    let cargo_commands = [
37      "add",
38      "bench",
39      "build",
40      "check",
41      "clean",
42      "clippy",
43      "doc",
44      "fix",
45      "fmt",
46      "init",
47      "install",
48      "miri",
49      "new",
50      "publish",
51      "remove",
52      "report",
53      "run",
54      "search",
55      "test",
56      "uninstall",
57      "update",
58    ];
59
60    let hm: HashMap<String, Task> = cargo_commands
61      .iter()
62      .map(|cmd| (cmd.to_string(), Task::String(format!("cargo {}", cmd))))
63      .collect();
64    Ok(hm)
65  }
66}