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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use anyhow::Result;
use xshell::{cmd, Shell};

use crate::commands::cargo_cmd;
use crate::utils::{project_root, verbose_cd};
use crate::Config;

pub fn install_rust_deps(config: &Config) -> Result<()> {
    let sh = Shell::new()?;
    verbose_cd(&sh, project_root());

    cmd!(sh, "rustup toolchain add stable --component clippy").run()?;
    cmd!(sh, "rustup toolchain add nightly --component rustfmt").run()?;

    let cmd_option = cargo_cmd(config, &sh);
    if let Some(cmd) = cmd_option {
        let args = vec![
            "install",
            "cargo-insta",
            "cargo-llvm-cov",
            "cargo-nextest",
            "cargo-watch",
        ];
        cmd.args(args).run()?;
    }

    Ok(())
}

pub fn test_with_snapshots(config: &Config) -> Result<()> {
    let sh = Shell::new()?;
    verbose_cd(&sh, project_root());

    let cmd_option = cargo_cmd(config, &sh);
    if let Some(cmd) = cmd_option {
        let args = vec!["insta", "test", "--test-runner", "nextest"];
        cmd.args(args).run()?;
    }

    Ok(())
}

pub fn watch_clippy(config: &Config) -> Result<()> {
    let sh = Shell::new()?;
    verbose_cd(&sh, project_root());

    println!("\nPress Ctrl-C to stop the program.");

    let cmd_option = cargo_cmd(config, &sh);
    if let Some(cmd) = cmd_option {
        let args = vec!["watch", "--why", "-x", "clippy --locked --all-targets"];
        cmd.args(args).run()?;
    }

    Ok(())
}

pub fn watch_doc(config: &Config) -> Result<()> {
    let sh = Shell::new()?;
    verbose_cd(&sh, project_root());

    let cmd_option = cargo_cmd(config, &sh);
    if let Some(_cmd) = cmd_option {
        let args = vec!["doc", "--no-deps", "--open"];
        cargo_cmd(config, &sh).unwrap().args(args).run()?;

        println!("\nPress Ctrl-C to stop the program.");

        let args = vec!["watch", "--postpone", "--why", "-x", "doc --no-deps"];
        cargo_cmd(config, &sh).unwrap().args(args).run()?;
    }

    Ok(())
}