xtask/
main.rs

1use std::fmt::Display;
2
3use clap::{Parser, ValueEnum};
4
5mod clippy;
6mod tests;
7mod tidy;
8mod utils;
9
10#[derive(Debug, Parser)]
11enum Commands {
12    /// Run all tests for diesel
13    ///
14    /// Requires `cargo-nextest` to be installed
15    RunTests(tests::TestArgs),
16    /// Run clippy on all crates
17    Clippy(clippy::ClippyArgs),
18    /// Perform a set of preliminary checks
19    ///
20    /// This command will execute `cargo fmt --check` to verify that
21    /// the code is formatted, `typos` to check for spelling errors
22    /// and it will execute `xtask clippy` to verify that the code
23    /// compiles without warning
24    Tidy(tidy::TidyArgs),
25}
26
27impl Commands {
28    fn run(self) {
29        match self {
30            Commands::RunTests(test_args) => test_args.run(),
31            Commands::Clippy(clippy) => clippy.run(),
32            Commands::Tidy(tidy) => tidy.run(),
33        }
34    }
35}
36
37#[derive(Debug, Clone, Copy, ValueEnum)]
38enum Backend {
39    Postgres,
40    Sqlite,
41    Mysql,
42    All,
43}
44
45impl Backend {
46    const ALL: &'static [Self] = &[Backend::Postgres, Backend::Sqlite, Backend::Mysql];
47}
48
49impl Display for Backend {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        match self {
52            Backend::Postgres => write!(f, "postgres"),
53            Backend::Sqlite => write!(f, "sqlite"),
54            Backend::Mysql => write!(f, "mysql"),
55            Backend::All => write!(f, "all"),
56        }
57    }
58}
59
60fn main() {
61    dotenvy::dotenv().ok();
62    Commands::parse().run();
63}