xtask/
main.rs

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
use std::fmt::Display;

use clap::{Parser, ValueEnum};

mod clippy;
mod tests;
mod tidy;
mod utils;

#[derive(Debug, Parser)]
enum Commands {
    /// Run all tests for diesel
    ///
    /// Requires `cargo-nextest` to be installed
    RunTests(tests::TestArgs),
    /// Run clippy on all crates
    Clippy(clippy::ClippyArgs),
    /// Perform a set of preliminary checks
    ///
    /// This command will execute `cargo fmt --check` to verify that
    /// the code is formatted, `typos` to check for spelling errors
    /// and it will execute `xtask clippy` to verify that the code
    /// compiles without warning
    Tidy(tidy::TidyArgs),
}

impl Commands {
    fn run(self) {
        match self {
            Commands::RunTests(test_args) => test_args.run(),
            Commands::Clippy(clippy) => clippy.run(),
            Commands::Tidy(tidy) => tidy.run(),
        }
    }
}

#[derive(Debug, Clone, Copy, ValueEnum)]
enum Backend {
    Postgres,
    Sqlite,
    Mysql,
    All,
}

impl Backend {
    const ALL: &'static [Self] = &[Backend::Postgres, Backend::Sqlite, Backend::Mysql];
}

impl Display for Backend {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Backend::Postgres => write!(f, "postgres"),
            Backend::Sqlite => write!(f, "sqlite"),
            Backend::Mysql => write!(f, "mysql"),
            Backend::All => write!(f, "all"),
        }
    }
}

fn main() {
    dotenvy::dotenv().ok();
    Commands::parse().run();
}