2024-04-18 12:28:28 +03:00
|
|
|
use anyhow::{bail, Context, Result};
|
2024-04-16 00:54:57 +03:00
|
|
|
use clap::Subcommand;
|
2024-05-01 20:47:35 +03:00
|
|
|
use std::path::PathBuf;
|
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:45:16 +03:00
|
|
|
/// Create a new project for third-party Rustlings exercises
|
2024-04-22 01:38:34 +03:00
|
|
|
New {
|
2024-04-22 01:45:16 +03:00
|
|
|
/// The path to create the project in
|
2024-04-22 01:38:34 +03:00
|
|
|
path: PathBuf,
|
2024-04-29 18:01:47 +03:00
|
|
|
/// Don't try to initialize a Git repository in the project directory
|
2024-04-22 01:38:34 +03:00
|
|
|
#[arg(long)]
|
|
|
|
no_git: bool,
|
|
|
|
},
|
2024-04-22 01:45:16 +03:00
|
|
|
/// Run checks on the exercises
|
2024-06-02 01:11:41 +03:00
|
|
|
Check {
|
|
|
|
/// Require that every exercise has a solution
|
|
|
|
#[arg(short, long)]
|
|
|
|
require_solutions: bool,
|
|
|
|
},
|
2024-04-22 01:45:16 +03:00
|
|
|
/// Update the `Cargo.toml` file for the exercises
|
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-25 16:58:46 +03:00
|
|
|
Self::New { path, no_git } => {
|
2024-08-01 16:23:54 +03:00
|
|
|
if cfg!(debug_assertions) {
|
2024-04-21 20:26:19 +03:00
|
|
|
bail!("Disabled in the debug build");
|
2024-04-18 12:28:28 +03:00
|
|
|
}
|
|
|
|
|
2024-04-22 01:38:34 +03:00
|
|
|
new::new(&path, no_git).context(INIT_ERR)
|
2024-04-18 12:28:28 +03:00
|
|
|
}
|
2024-06-02 01:11:41 +03:00
|
|
|
Self::Check { require_solutions } => check::check(require_solutions),
|
2024-04-25 16:58:46 +03:00
|
|
|
Self::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";
|