rustlings/src/dev.rs

35 lines
774 B
Rust
Raw Normal View History

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-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-21 23:43:49 +02:00
New { path: String },
2024-04-15 23:54:57 +02:00
Check,
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-21 23:43:49 +02:00
DevCommands::New { path } => {
2024-04-21 19:26:19 +02:00
if DEBUG_PROFILE {
bail!("Disabled in the debug build");
}
2024-04-21 23:43:49 +02:00
new::init().context(INIT_ERR)
}
2024-04-17 15:55:50 +02:00
DevCommands::Check => check::check(),
DevCommands::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";