summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs
index e42dff4..5a4af53 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,8 +25,13 @@ fn main() {
SubCommand::with_name("run")
.alias("r")
.about("Runs/Tests a single exercise")
- .arg(Arg::with_name("file").required(true).index(1))
- .arg(Arg::with_name("test").short("t").long("test").help("Run the file as a test")),
+ .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();
@@ -55,26 +60,38 @@ fn main() {
let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises;
if let Some(ref matches) = matches.subcommand_matches("run") {
- let filename = matches.value_of("file").unwrap_or_else(|| {
- println!("Please supply a file name!");
+ let name = matches.value_of("name").unwrap_or_else(|| {
+ println!("Please supply an exercise name!");
std::process::exit(1);
});
- let matching_exercise = |e: &&Exercise| {
- Path::new(filename)
- .canonicalize()
- .map(|p| p.ends_with(&e.path))
- .unwrap_or(false)
- };
+ let matching_exercise = |e: &&Exercise| name == e.name;
let exercise = exercises.iter().find(matching_exercise).unwrap_or_else(|| {
- println!("No exercise found for your file name!");
+ println!("No exercise found for your given name!");
std::process::exit(1)
});
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));
}