mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-24 14:37:32 -05:00
Scetch the dev subcommand
This commit is contained in:
parent
f5eaa578b9
commit
7ebc260924
4 changed files with 39 additions and 12 deletions
20
src/dev.rs
Normal file
20
src/dev.rs
Normal file
|
@ -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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
src/dev/check.rs
Normal file
5
src/dev/check.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
pub fn check() -> Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
5
src/dev/init.rs
Normal file
5
src/dev/init.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
pub fn init() -> Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
21
src/main.rs
21
src/main.rs
|
@ -12,6 +12,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
mod app_state;
|
mod app_state;
|
||||||
|
mod dev;
|
||||||
mod embedded;
|
mod embedded;
|
||||||
mod exercise;
|
mod exercise;
|
||||||
mod info_file;
|
mod info_file;
|
||||||
|
@ -21,14 +22,7 @@ mod progress_bar;
|
||||||
mod run;
|
mod run;
|
||||||
mod watch;
|
mod watch;
|
||||||
|
|
||||||
use self::{
|
use self::{app_state::AppState, dev::DevCommands, info_file::InfoFile, watch::WatchExit};
|
||||||
app_state::AppState,
|
|
||||||
info_file::InfoFile,
|
|
||||||
init::init,
|
|
||||||
list::list,
|
|
||||||
run::run,
|
|
||||||
watch::{watch, WatchExit},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code
|
/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -61,6 +55,8 @@ enum Subcommands {
|
||||||
/// The name of the exercise
|
/// The name of the exercise
|
||||||
name: String,
|
name: String,
|
||||||
},
|
},
|
||||||
|
#[command(subcommand)]
|
||||||
|
Dev(DevCommands),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
@ -71,7 +67,7 @@ fn main() -> Result<()> {
|
||||||
let info_file = InfoFile::parse()?;
|
let info_file = InfoFile::parse()?;
|
||||||
|
|
||||||
if matches!(args.command, Some(Subcommands::Init)) {
|
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}");
|
println!("{POST_INIT_MSG}");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -122,12 +118,12 @@ fn main() -> Result<()> {
|
||||||
};
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match watch(&mut app_state, notify_exercise_paths)? {
|
match watch::watch(&mut app_state, notify_exercise_paths)? {
|
||||||
WatchExit::Shutdown => break,
|
WatchExit::Shutdown => break,
|
||||||
// It is much easier to exit the watch mode, launch the list mode and then restart
|
// 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
|
// the watch mode instead of trying to pause the watch threads and correct the
|
||||||
// watch state.
|
// 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 {
|
if let Some(name) = name {
|
||||||
app_state.set_current_exercise_by_name(&name)?;
|
app_state.set_current_exercise_by_name(&name)?;
|
||||||
}
|
}
|
||||||
run(&mut app_state)?;
|
run::run(&mut app_state)?;
|
||||||
}
|
}
|
||||||
Some(Subcommands::Reset { name }) => {
|
Some(Subcommands::Reset { name }) => {
|
||||||
app_state.set_current_exercise_by_name(&name)?;
|
app_state.set_current_exercise_by_name(&name)?;
|
||||||
|
@ -150,6 +146,7 @@ fn main() -> Result<()> {
|
||||||
app_state.set_current_exercise_by_name(&name)?;
|
app_state.set_current_exercise_by_name(&name)?;
|
||||||
println!("{}", app_state.current_exercise().hint);
|
println!("{}", app_state.current_exercise().hint);
|
||||||
}
|
}
|
||||||
|
Some(Subcommands::Dev(dev_command)) => dev_command.run()?,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue