xtask/
main.rs

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