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.
This commit is contained in:
@@ -27,6 +27,7 @@ pub struct Exercise {
|
||||
pub name: String,
|
||||
pub path: PathBuf,
|
||||
pub mode: Mode,
|
||||
pub hint: String,
|
||||
}
|
||||
|
||||
impl Exercise {
|
||||
@@ -74,6 +75,7 @@ mod test {
|
||||
name: String::from("example"),
|
||||
path: PathBuf::from("example.rs"),
|
||||
mode: Mode::Test,
|
||||
hint: String::from(""),
|
||||
};
|
||||
exercise.clean();
|
||||
assert!(!Path::new(&temp_file()).exists());
|
||||
|
||||
20
src/main.rs
20
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user