Merge pull request #707 from Zerotask/list-command-progress-info
feat(list): added progress info
This commit is contained in:
commit
e2ce9f42b5
@ -1,6 +1,6 @@
|
|||||||
use std::env;
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::env;
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
use std::fs::{self, remove_file, File};
|
use std::fs::{self, remove_file, File};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
@ -132,8 +132,7 @@ path = "{}.rs""#,
|
|||||||
} else {
|
} else {
|
||||||
"Failed to write 📎 Clippy 📎 Cargo.toml file."
|
"Failed to write 📎 Clippy 📎 Cargo.toml file."
|
||||||
};
|
};
|
||||||
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml)
|
fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml).expect(cargo_toml_error_msg);
|
||||||
.expect(cargo_toml_error_msg);
|
|
||||||
// To support the ability to run the clipy exercises, build
|
// To support the ability to run the clipy exercises, build
|
||||||
// an executable, in addition to running clippy. With a
|
// an executable, in addition to running clippy. With a
|
||||||
// compilation failure, this would silently fail. But we expect
|
// compilation failure, this would silently fail. But we expect
|
||||||
|
17
src/main.rs
17
src/main.rs
@ -138,13 +138,19 @@ fn main() {
|
|||||||
println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status");
|
println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status");
|
||||||
}
|
}
|
||||||
let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase();
|
let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase();
|
||||||
|
let mut exercises_done: u16 = 0;
|
||||||
exercises.iter().for_each(|e| {
|
exercises.iter().for_each(|e| {
|
||||||
let fname = format!("{}", e.path.display());
|
let fname = format!("{}", e.path.display());
|
||||||
let filter_cond = filters
|
let filter_cond = filters
|
||||||
.split(',')
|
.split(',')
|
||||||
.filter(|f| !f.trim().is_empty())
|
.filter(|f| !f.trim().is_empty())
|
||||||
.any(|f| e.name.contains(&f) || fname.contains(&f));
|
.any(|f| e.name.contains(&f) || fname.contains(&f));
|
||||||
let status = if e.looks_done() { "Done" } else { "Pending" };
|
let status = if e.looks_done() {
|
||||||
|
exercises_done = exercises_done + 1;
|
||||||
|
"Done"
|
||||||
|
} else {
|
||||||
|
"Pending"
|
||||||
|
};
|
||||||
let solve_cond = {
|
let solve_cond = {
|
||||||
(e.looks_done() && list_m.is_present("solved"))
|
(e.looks_done() && list_m.is_present("solved"))
|
||||||
|| (!e.looks_done() && list_m.is_present("unsolved"))
|
|| (!e.looks_done() && list_m.is_present("unsolved"))
|
||||||
@ -173,6 +179,13 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
let percentage_progress = exercises_done as f32 / exercises.len() as f32 * 100.0;
|
||||||
|
println!(
|
||||||
|
"Progress: You completed {} / {} exercises ({:.2} %).",
|
||||||
|
exercises_done,
|
||||||
|
exercises.len(),
|
||||||
|
percentage_progress
|
||||||
|
);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +327,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {
|
|||||||
.chain(
|
.chain(
|
||||||
exercises
|
exercises
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path))
|
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)),
|
||||||
);
|
);
|
||||||
clear_screen();
|
clear_screen();
|
||||||
match verify(pending_exercises, verbose) {
|
match verify(pending_exercises, verbose) {
|
||||||
|
16
src/ui.rs
16
src/ui.rs
@ -1,14 +1,10 @@
|
|||||||
macro_rules! warn {
|
macro_rules! warn {
|
||||||
($fmt:literal, $ex:expr) => {{
|
($fmt:literal, $ex:expr) => {{
|
||||||
use std::env;
|
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
|
use std::env;
|
||||||
let formatstr = format!($fmt, $ex);
|
let formatstr = format!($fmt, $ex);
|
||||||
if env::var("NO_EMOJI").is_ok() {
|
if env::var("NO_EMOJI").is_ok() {
|
||||||
println!(
|
println!("{} {}", style("!").red(), style(formatstr).red());
|
||||||
"{} {}",
|
|
||||||
style("!").red(),
|
|
||||||
style(formatstr).red()
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
println!(
|
println!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
@ -21,15 +17,11 @@ macro_rules! warn {
|
|||||||
|
|
||||||
macro_rules! success {
|
macro_rules! success {
|
||||||
($fmt:literal, $ex:expr) => {{
|
($fmt:literal, $ex:expr) => {{
|
||||||
use std::env;
|
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
|
use std::env;
|
||||||
let formatstr = format!($fmt, $ex);
|
let formatstr = format!($fmt, $ex);
|
||||||
if env::var("NO_EMOJI").is_ok() {
|
if env::var("NO_EMOJI").is_ok() {
|
||||||
println!(
|
println!("{} {}", style("✓").green(), style(formatstr).green());
|
||||||
"{} {}",
|
|
||||||
style("✓").green(),
|
|
||||||
style(formatstr).green()
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
println!(
|
println!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::env;
|
|
||||||
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
|
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
|
||||||
use console::style;
|
use console::style;
|
||||||
use indicatif::ProgressBar;
|
use indicatif::ProgressBar;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
// Verify that the provided container of Exercise objects
|
// Verify that the provided container of Exercise objects
|
||||||
// can be compiled and run without any failures.
|
// can be compiled and run without any failures.
|
||||||
|
Loading…
Reference in New Issue
Block a user