2024-04-21 18:34:55 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2024-04-18 05:28:28 -04:00
|
|
|
use anyhow::{bail, Context, Result};
|
2024-04-15 17:54:57 -04:00
|
|
|
use clap::Subcommand;
|
|
|
|
|
2024-04-21 13:26:19 -04:00
|
|
|
use crate::DEBUG_PROFILE;
|
2024-04-18 05:28:28 -04:00
|
|
|
|
2024-04-15 17:54:57 -04:00
|
|
|
mod check;
|
2024-04-21 17:43:49 -04:00
|
|
|
mod new;
|
2024-04-17 09:55:50 -04:00
|
|
|
mod update;
|
2024-04-15 17:54:57 -04:00
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
pub enum DevCommands {
|
2024-04-21 18:45:16 -04:00
|
|
|
/// Create a new project for third-party Rustlings exercises
|
2024-04-21 18:38:34 -04:00
|
|
|
New {
|
2024-04-21 18:45:16 -04:00
|
|
|
/// The path to create the project in
|
2024-04-21 18:38:34 -04:00
|
|
|
path: PathBuf,
|
2024-04-21 18:45:16 -04:00
|
|
|
/// Don't initialize a Git repository in the project directory
|
2024-04-21 18:38:34 -04:00
|
|
|
#[arg(long)]
|
|
|
|
no_git: bool,
|
|
|
|
},
|
2024-04-21 18:45:16 -04:00
|
|
|
/// Run checks on the exercises
|
2024-04-15 17:54:57 -04:00
|
|
|
Check,
|
2024-04-21 18:45:16 -04:00
|
|
|
/// Update the `Cargo.toml` file for the exercises
|
2024-04-17 09:55:50 -04:00
|
|
|
Update,
|
2024-04-15 17:54:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DevCommands {
|
2024-04-17 09:55:50 -04:00
|
|
|
pub fn run(self) -> Result<()> {
|
2024-04-15 17:54:57 -04:00
|
|
|
match self {
|
2024-04-25 09:58:46 -04:00
|
|
|
Self::New { path, no_git } => {
|
2024-04-21 13:26:19 -04:00
|
|
|
if DEBUG_PROFILE {
|
|
|
|
bail!("Disabled in the debug build");
|
2024-04-18 05:28:28 -04:00
|
|
|
}
|
|
|
|
|
2024-04-21 18:38:34 -04:00
|
|
|
new::new(&path, no_git).context(INIT_ERR)
|
2024-04-18 05:28:28 -04:00
|
|
|
}
|
2024-04-25 09:58:46 -04:00
|
|
|
Self::Check => check::check(),
|
|
|
|
Self::Update => update::update(),
|
2024-04-15 17:54:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-15 21:08:45 -04:00
|
|
|
|
|
|
|
const INIT_ERR: &str = "Initialization failed.
|
|
|
|
After resolving the issue, delete the `rustlings` directory (if it was created) and try again";
|