diff options
| author | marisa <mokou@posteo.de> | 2019-11-11 16:51:38 +0100 |
|---|---|---|
| committer | marisa <mokou@posteo.de> | 2019-11-11 16:51:38 +0100 |
| commit | 9bdb0a12e45a8e9f9f6a4bd4a9c172c5376c7f60 (patch) | |
| tree | 3c4a094d57ecedf9706e0ba567a9f157590177c8 /src/main.rs | |
| parent | 627cdc07d07dfe6a740e885e0ddf6900e7ec336b (diff) | |
feat: Refactor hint system
Hints are now accessible using the CLI subcommand `rustlings hint
<exercise name`.
BREAKING CHANGE: This fundamentally changes the way people interact with exercises.
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 100186b..69a7b22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,12 @@ fn main() { .about("Runs/Tests a single exercise") .arg(Arg::with_name("name").required(true).index(1)), ) + .subcommand( + SubCommand::with_name("hint") + .alias("h") + .about("Returns a hint for the current exercise") + .arg(Arg::with_name("name").required(true).index(1)), + ) .get_matches(); if None == matches.subcommand_name() { @@ -71,6 +77,20 @@ fn main() { run(&exercise).unwrap_or_else(|_| std::process::exit(1)); } + if let Some(ref matches) = matches.subcommand_matches("hint") { + let name = matches.value_of("name").unwrap_or_else(|| { + println!("Please supply an exercise name!"); + std::process::exit(1); + }); + + let exercise = exercises.iter().find(|e| name == e.name).unwrap_or_else(|| { + println!("No exercise found for your given name!"); + std::process::exit(1) + }); + + println!("{}", exercise.hint); + } + if matches.subcommand_matches("verify").is_some() { verify(&exercises).unwrap_or_else(|_| std::process::exit(1)); } |
