From 7ebc260924f5db0099568589f2be621c9ea43721 Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 15 Apr 2024 23:54:57 +0200 Subject: [PATCH] Scetch the dev subcommand --- src/dev.rs | 20 ++++++++++++++++++++ src/dev/check.rs | 5 +++++ src/dev/init.rs | 5 +++++ src/main.rs | 21 +++++++++------------ 4 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 src/dev.rs create mode 100644 src/dev/check.rs create mode 100644 src/dev/init.rs diff --git a/src/dev.rs b/src/dev.rs new file mode 100644 index 0000000..40382a8 --- /dev/null +++ b/src/dev.rs @@ -0,0 +1,20 @@ +use anyhow::Result; +use clap::Subcommand; + +mod check; +mod init; + +#[derive(Subcommand)] +pub enum DevCommands { + Init, + Check, +} + +impl DevCommands { + pub fn run(self) -> Result<()> { + match self { + DevCommands::Init => init::init(), + DevCommands::Check => check::check(), + } + } +} diff --git a/src/dev/check.rs b/src/dev/check.rs new file mode 100644 index 0000000..46d3ffe --- /dev/null +++ b/src/dev/check.rs @@ -0,0 +1,5 @@ +use anyhow::Result; + +pub fn check() -> Result<()> { + todo!() +} diff --git a/src/dev/init.rs b/src/dev/init.rs new file mode 100644 index 0000000..01cfd9f --- /dev/null +++ b/src/dev/init.rs @@ -0,0 +1,5 @@ +use anyhow::Result; + +pub fn init() -> Result<()> { + todo!() +} diff --git a/src/main.rs b/src/main.rs index 541783d..e72dbdc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use std::{ }; mod app_state; +mod dev; mod embedded; mod exercise; mod info_file; @@ -21,14 +22,7 @@ mod progress_bar; mod run; mod watch; -use self::{ - app_state::AppState, - info_file::InfoFile, - init::init, - list::list, - run::run, - watch::{watch, WatchExit}, -}; +use self::{app_state::AppState, dev::DevCommands, info_file::InfoFile, watch::WatchExit}; /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code #[derive(Parser)] @@ -61,6 +55,8 @@ enum Subcommands { /// The name of the exercise name: String, }, + #[command(subcommand)] + Dev(DevCommands), } fn main() -> Result<()> { @@ -71,7 +67,7 @@ fn main() -> Result<()> { let info_file = InfoFile::parse()?; if matches!(args.command, Some(Subcommands::Init)) { - init(&info_file.exercises).context("Initialization failed")?; + init::init(&info_file.exercises).context("Initialization failed")?; println!("{POST_INIT_MSG}"); return Ok(()); } @@ -122,12 +118,12 @@ fn main() -> Result<()> { }; loop { - match watch(&mut app_state, notify_exercise_paths)? { + match watch::watch(&mut app_state, notify_exercise_paths)? { WatchExit::Shutdown => break, // It is much easier to exit the watch mode, launch the list mode and then restart // the watch mode instead of trying to pause the watch threads and correct the // watch state. - WatchExit::List => list(&mut app_state)?, + WatchExit::List => list::list(&mut app_state)?, } } } @@ -137,7 +133,7 @@ fn main() -> Result<()> { if let Some(name) = name { app_state.set_current_exercise_by_name(&name)?; } - run(&mut app_state)?; + run::run(&mut app_state)?; } Some(Subcommands::Reset { name }) => { app_state.set_current_exercise_by_name(&name)?; @@ -150,6 +146,7 @@ fn main() -> Result<()> { app_state.set_current_exercise_by_name(&name)?; println!("{}", app_state.current_exercise().hint); } + Some(Subcommands::Dev(dev_command)) => dev_command.run()?, } Ok(())