rustlings/src/dev.rs

41 lines
876 B
Rust
Raw Normal View History

use std::path::PathBuf;
use anyhow::{bail, Context, Result};
2024-04-16 00:54:57 +03:00
use clap::Subcommand;
2024-04-21 20:26:19 +03:00
use crate::DEBUG_PROFILE;
2024-04-16 00:54:57 +03:00
mod check;
2024-04-22 00:43:49 +03:00
mod new;
2024-04-17 16:55:50 +03:00
mod update;
2024-04-16 00:54:57 +03:00
#[derive(Subcommand)]
pub enum DevCommands {
2024-04-22 01:38:34 +03:00
New {
path: PathBuf,
#[arg(long)]
no_git: bool,
},
2024-04-16 00:54:57 +03:00
Check,
2024-04-17 16:55:50 +03:00
Update,
2024-04-16 00:54:57 +03:00
}
impl DevCommands {
2024-04-17 16:55:50 +03:00
pub fn run(self) -> Result<()> {
2024-04-16 00:54:57 +03:00
match self {
2024-04-22 01:38:34 +03:00
DevCommands::New { path, no_git } => {
2024-04-21 20:26:19 +03:00
if DEBUG_PROFILE {
bail!("Disabled in the debug build");
}
2024-04-22 01:38:34 +03:00
new::new(&path, no_git).context(INIT_ERR)
}
2024-04-17 16:55:50 +03:00
DevCommands::Check => check::check(),
DevCommands::Update => update::update(),
2024-04-16 00:54:57 +03:00
}
}
}
2024-04-16 04:08:45 +03:00
const INIT_ERR: &str = "Initialization failed.
After resolving the issue, delete the `rustlings` directory (if it was created) and try again";