diff options
| author | mo8it <mo8it@proton.me> | 2024-07-05 13:39:50 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-07-05 13:39:50 +0200 |
| commit | 7123c7ae3a9605fbe962e4ef0a0f1424cd16fef8 (patch) | |
| tree | c67f7e62bb9a179ae4fdbab492501cb6847e64c7 /src/dev.rs | |
| parent | 77b687d501771c24bd83294d97b8e6f9ffa92d6b (diff) | |
| parent | 4d9c346a173bb722b929f3ea3c00f84954483e24 (diff) | |
Merge remote-tracking branch 'upstream/main' into fix-enum-variant-inconsistency
Diffstat (limited to 'src/dev.rs')
| -rw-r--r-- | src/dev.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/dev.rs b/src/dev.rs new file mode 100644 index 0000000..5f7e64c --- /dev/null +++ b/src/dev.rs @@ -0,0 +1,48 @@ +use anyhow::{bail, Context, Result}; +use clap::Subcommand; +use std::path::PathBuf; + +use crate::DEBUG_PROFILE; + +mod check; +mod new; +mod update; + +#[derive(Subcommand)] +pub enum DevCommands { + /// Create a new project for third-party Rustlings exercises + New { + /// The path to create the project in + path: PathBuf, + /// Don't try to initialize a Git repository in the project directory + #[arg(long)] + no_git: bool, + }, + /// Run checks on the exercises + Check { + /// Require that every exercise has a solution + #[arg(short, long)] + require_solutions: bool, + }, + /// Update the `Cargo.toml` file for the exercises + Update, +} + +impl DevCommands { + pub fn run(self) -> Result<()> { + match self { + Self::New { path, no_git } => { + if DEBUG_PROFILE { + bail!("Disabled in the debug build"); + } + + new::new(&path, no_git).context(INIT_ERR) + } + Self::Check { require_solutions } => check::check(require_solutions), + Self::Update => update::update(), + } + } +} + +const INIT_ERR: &str = "Initialization failed. +After resolving the issue, delete the `rustlings` directory (if it was created) and try again"; |
