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