summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/about_variables.rs38
-rw-r--r--src/helpers.rs33
-rw-r--r--src/main.rs55
3 files changed, 39 insertions, 87 deletions
diff --git a/src/about_variables.rs b/src/about_variables.rs
deleted file mode 100644
index 1587dc0..0000000
--- a/src/about_variables.rs
+++ /dev/null
@@ -1,38 +0,0 @@
-use helpers::*;
-
-// Variables in Rust are defined using the "let" keyword. Like this:
-
-fn exercise_one() {
- let x = 5;
- verify(5, x);
- // ^ ^
- // | |
- // What's The variable
- // in it name
-}
-
-// Try to replace the "0" with the value of the variable, then run
-// "cargo run" and see if it was correct!
-
-// Here's a more complicated example:
-
-fn guess_me() -> &'static str {
- let x = 10;
- if x == 10 {
- return "Ten!";
- } else {
- return "Not ten!";
- }
-}
-
-fn exercise_two() {
- let result = guess_me();
- verify("REPLACE ME", result);
-}
-
-pub fn exec() {
- title("Variables: Exercise 1");
- exercise_one();
- title("Variables: Exercise 2");
- exercise_two();
-}
diff --git a/src/helpers.rs b/src/helpers.rs
deleted file mode 100644
index e0b560b..0000000
--- a/src/helpers.rs
+++ /dev/null
@@ -1,33 +0,0 @@
-use ansi_term::Color::{Green, Red, Yellow};
-use std::fmt::Display;
-
-pub fn verify<T: PartialEq + Display>(left: T, right: T) {
- if left == right {
- println!("{} {} == {}", Green.bold().paint("PASS"), left, right);
- } else {
- println!(
- "{} You submitted {}, but that's not correct!",
- Red.bold().paint("FAIL"),
- left
- );
- println!(" Please correct your code to make this test pass!");
- }
-}
-
-pub fn verify_easy<T: PartialEq + Display>(left: T, right: T) {
- if left == right {
- println!("{} {} == {}", Green.bold().paint("PASS"), left, right);
- } else {
- println!(
- "{} You submitted {}, but that's not correct!",
- Red.bold().paint("FAIL"),
- left
- );
- println!(" Expected: {}", right);
- println!(" Please correct your code to make this test pass!");
- }
-}
-
-pub fn title(s: &str) {
- println!("{} {}", Yellow.bold().paint("RUN"), s);
-}
diff --git a/src/main.rs b/src/main.rs
index 02f0227..cf2eddd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,21 +1,44 @@
#[macro_use]
-extern crate quicli;
-extern crate ansi_term;
+extern crate clap;
+extern crate indicatif;
+extern crate console;
-use ansi_term::Color::Yellow;
-use quicli::prelude::*;
+use clap::{App, SubCommand};
+use indicatif::{ProgressBar};
+use console::{style, Emoji};
+use std::process::Command;
-mod helpers;
-mod about_variables;
-
-#[derive(Debug, StructOpt)]
-struct Cli {
- exercise: Option<String>,
+fn main() {
+ let matches = App::new("r2")
+ .version(crate_version!())
+ .author("Olivia Hugger")
+ .about("Test")
+ .subcommand(SubCommand::with_name("verify").alias("v"))
+ .get_matches();
+
+ if let Some(_) = matches.subcommand_matches("verify") {
+ execute("exercises/ex1.rs");
+ execute("exercises/ex2.rs");
+ execute("exercises/ex3.rs");
+ execute("exercises/ex4.rs");
+ execute("exercises/ex5.rs");
+ }
}
-main!(|args: Cli| if let Some(e) = args.exercise {
- println!("selected {}", e);
-} else {
- println!("Welcome to {}!\n", Yellow.paint("Rustlings"));
- about_variables::exec();
-});
+fn execute(filename: &str) {
+ let bar = ProgressBar::new_spinner();
+ bar.set_message(format!("Compiling {}...", filename).as_str());
+ bar.enable_steady_tick(100);
+ let compilecmd = Command::new("rustc")
+ .args(&[filename, "-o", "temp"])
+ .output()
+ .expect("fail");
+ bar.finish_and_clear();
+ if compilecmd.status.success() {
+ println!("{} Successfully compiled {}!", Emoji("✅", "✓"), style(filename).italic());
+ } else {
+ println!("{} Compilation of {} failed! Compiler error message:\n", Emoji("⚠️ ", "!"), style(filename).italic());
+ println!("{}", String::from_utf8_lossy(&compilecmd.stderr));
+ std::process::exit(1);
+ }
+}