feat(cli): added success-hints option for the rustlings command
closes #1373
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -37,6 +37,9 @@ struct Args {
|
||||
/// show the executable version
|
||||
#[argh(switch, short = 'v')]
|
||||
version: bool,
|
||||
/// show hints on success
|
||||
#[argh(switch)]
|
||||
success_hints: bool,
|
||||
#[argh(subcommand)]
|
||||
nested: Option<Subcommands>,
|
||||
}
|
||||
@@ -148,6 +151,7 @@ fn main() {
|
||||
let toml_str = &fs::read_to_string("info.toml").unwrap();
|
||||
let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises;
|
||||
let verbose = args.nocapture;
|
||||
let success_hints = args.success_hints;
|
||||
|
||||
let command = args.nested.unwrap_or_else(|| {
|
||||
println!("{DEFAULT_OUT}\n");
|
||||
@@ -229,7 +233,7 @@ fn main() {
|
||||
}
|
||||
|
||||
Subcommands::Verify(_subargs) => {
|
||||
verify(&exercises, (0, exercises.len()), verbose)
|
||||
verify(&exercises, (0, exercises.len()), verbose, success_hints)
|
||||
.unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
@@ -252,7 +256,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
Subcommands::Watch(_subargs) => match watch(&exercises, verbose) {
|
||||
Subcommands::Watch(_subargs) => match watch(&exercises, verbose, success_hints) {
|
||||
Err(e) => {
|
||||
println!(
|
||||
"Error: Could not watch your progress. Error message was {:?}.",
|
||||
@@ -348,7 +352,7 @@ enum WatchStatus {
|
||||
Unfinished,
|
||||
}
|
||||
|
||||
fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
fn watch(exercises: &[Exercise], verbose: bool, success_hints: bool) -> notify::Result<WatchStatus> {
|
||||
/* Clears the terminal with an ANSI escape code.
|
||||
Works in UNIX and newer Windows terminals. */
|
||||
fn clear_screen() {
|
||||
@@ -364,7 +368,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
clear_screen();
|
||||
|
||||
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
|
||||
let failed_exercise_hint = match verify(exercises.iter(), (0, exercises.len()), verbose) {
|
||||
let failed_exercise_hint = match verify(exercises.iter(), (0, exercises.len()), verbose, success_hints) {
|
||||
Ok(_) => return Ok(WatchStatus::Finished),
|
||||
Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))),
|
||||
};
|
||||
@@ -386,7 +390,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
);
|
||||
let num_done = exercises.iter().filter(|e| e.looks_done()).count();
|
||||
clear_screen();
|
||||
match verify(pending_exercises, (num_done, exercises.len()), verbose) {
|
||||
match verify(pending_exercises, (num_done, exercises.len()), verbose, success_hints) {
|
||||
Ok(_) => return Ok(WatchStatus::Finished),
|
||||
Err(exercise) => {
|
||||
let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user