rustlings/src/dev.rs

49 lines
1.3 KiB
Rust
Raw Normal View History

use anyhow::{bail, Context, Result};
2024-04-15 17:54:57 -04:00
use clap::Subcommand;
2024-05-01 13:47:35 -04:00
use std::path::PathBuf;
2024-04-15 17:54:57 -04:00
2024-04-21 13:26:19 -04:00
use crate::DEBUG_PROFILE;
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-29 11:01:47 -04:00
/// Don't try to 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
Check {
/// Require that every exercise has a solution
#[arg(short, long)]
require_solutions: bool,
},
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-21 18:38:34 -04:00
new::new(&path, no_git).context(INIT_ERR)
}
Self::Check { require_solutions } => check::check(require_solutions),
2024-04-25 09:58:46 -04:00
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";