summaryrefslogtreecommitdiff
path: root/src/dev.rs
blob: 38338cd0a4f221ae5fcabc35f535b0cbe83333fe (plain)
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
use std::path::PathBuf;

use anyhow::{bail, Context, Result};
use clap::Subcommand;

use crate::DEBUG_PROFILE;

mod check;
mod new;
mod update;

#[derive(Subcommand)]
pub enum DevCommands {
    /// Create a new project for third-party Rustlings exercises
    New {
        /// The path to create the project in
        path: PathBuf,
        /// Don't initialize a Git repository in the project directory
        #[arg(long)]
        no_git: bool,
    },
    /// Run checks on the exercises
    Check,
    /// Update the `Cargo.toml` file for the exercises
    Update,
}

impl DevCommands {
    pub fn run(self) -> Result<()> {
        match self {
            DevCommands::New { path, no_git } => {
                if DEBUG_PROFILE {
                    bail!("Disabled in the debug build");
                }

                new::new(&path, no_git).context(INIT_ERR)
            }
            DevCommands::Check => check::check(),
            DevCommands::Update => update::update(),
        }
    }
}

const INIT_ERR: &str = "Initialization failed.
After resolving the issue, delete the `rustlings` directory (if it was created) and try again";