Skip to content

Add option to move directly to the next koan #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions koans-framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct Command {
/// collection.
#[structopt(long, parse(from_os_str))]
pub path: PathBuf,
/// Move to the next koan automatically if the tests pass
#[structopt(long)]
pub auto_move: bool,
}

fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -39,16 +42,19 @@ fn main() -> Result<(), Box<dyn Error>> {
Some(next_koan) => {
println!("\t{}\n", info_style().paint("Eternity lies ahead of us, and behind. Your path is not yet finished. 🍂"));

let open_next = input::<String>()
.repeat_msg(format!(
"Do you want to open the next koan, {}? [y/n] ",
next_koan
))
.err("Please answer either yes or no.")
.add_test(|s| parse_bool(s).is_some())
.get();
let open_next = command.auto_move || {
let open_next = input::<String>()
.repeat_msg(format!(
"Do you want to open the next koan, {}? [y/n] ",
next_koan
))
.err("Please answer either yes or no.")
.add_test(|s| parse_bool(s).is_some())
.get();

if parse_bool(&open_next).unwrap() {
parse_bool(&open_next).unwrap()
};
if open_next {
let next_koan = koans.open_next().expect("Failed to open the next koan");
println!(
"{} {}",
Expand Down