1use anyhow::Result;
2use xshell::{Shell, cmd};
3
4use crate::Config;
5use crate::commands::cargo_cmd;
6use crate::utils::{project_root, verbose_cd};
7
8pub fn install_rust_deps(config: &Config) -> Result<()> {
9 let sh = Shell::new()?;
10 verbose_cd(&sh, project_root());
11
12 cmd!(sh, "rustup toolchain add stable --component clippy").run()?;
13 cmd!(sh, "rustup toolchain add nightly --component rustfmt").run()?;
14
15 let cmd_option = cargo_cmd(config, &sh);
16 if let Some(cmd) = cmd_option {
17 let args = vec![
18 "install",
19 "cargo-insta",
20 "cargo-llvm-cov",
21 "cargo-nextest",
22 "cargo-watch",
23 ];
24 cmd.args(args).run()?;
25 }
26
27 Ok(())
28}
29
30pub fn test_with_snapshots(config: &Config) -> Result<()> {
31 let sh = Shell::new()?;
32 verbose_cd(&sh, project_root());
33
34 let cmd_option = cargo_cmd(config, &sh);
35 if let Some(cmd) = cmd_option {
36 let args = vec!["insta", "test", "--test-runner", "nextest"];
37 cmd.args(args).run()?;
38 }
39
40 Ok(())
41}
42
43pub fn watch_clippy(config: &Config) -> Result<()> {
44 let sh = Shell::new()?;
45 verbose_cd(&sh, project_root());
46
47 println!("\nPress Ctrl-C to stop the program.");
48
49 let cmd_option = cargo_cmd(config, &sh);
50 if let Some(cmd) = cmd_option {
51 let args = vec!["watch", "--why", "-x", "clippy --locked --all-targets"];
52 cmd.args(args).run()?;
53 }
54
55 Ok(())
56}
57
58pub fn watch_doc(config: &Config) -> Result<()> {
59 let sh = Shell::new()?;
60 verbose_cd(&sh, project_root());
61
62 let cmd_option = cargo_cmd(config, &sh);
63 if let Some(_cmd) = cmd_option {
64 let args = vec!["doc", "--no-deps", "--open"];
65 cargo_cmd(config, &sh).unwrap().args(args).run()?;
66
67 println!("\nPress Ctrl-C to stop the program.");
68
69 let args = vec!["watch", "--postpone", "--why", "-x", "doc --no-deps"];
70 cargo_cmd(config, &sh).unwrap().args(args).run()?;
71 }
72
73 Ok(())
74}