Skip to content

Commit

Permalink
Add options to not run all checks if unneeded
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 14, 2020
1 parent 69266a3 commit 8be96b3
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,38 @@ mod license;
mod manual_traits;
mod types;

fn run_check<P: AsRef<Path>>(folder: P, gir_file: &str) -> types::CheckResult<bool> {
fn run_check<P: AsRef<Path>>(
folder: P,
gir_file: &str,
check_manual_traits: bool,
check_license: bool,
) -> types::CheckResult<bool> {
println!("=> Running for {}", folder.as_ref().display());
let result = manual_traits::run_check(&folder, gir_file)? && license::run_check(&folder)?;
let mut result = true;
if check_manual_traits {
result = manual_traits::run_check(&folder, gir_file)?;
}
if check_license {
result &= license::run_check(&folder)?;
}
println!("<= done");
Ok(result)
}

fn show_help() {
println!("== checker options ==");
println!(" --gir-file : Set gir file path to be used for all following folders");
println!(" -h | --help : Display this help");
println!(" --gir-file : Set gir file path to be used for all following folders");
println!(" -h | --help : Display this help");
println!(" --no-manual-traits : Don't run manual_traits check");
println!(" --no-license : Don't run license check");
println!("");
println!("Any other argument will be the folder to run `checker` into.");
}

fn main() -> types::CheckResult<()> {
let mut gir_file = "Gir.toml".to_owned();
let mut check_manual_traits = true;
let mut check_license = true;
let mut result = true;
let args = env::args().into_iter().skip(1).collect::<Vec<_>>();
let mut i = 0;
Expand All @@ -48,10 +63,15 @@ fn main() -> types::CheckResult<()> {
} else if arg == "--help" || arg == "-h" {
show_help();
return Ok(());
} else if arg == "--no-manual-traits" {
check_manual_traits = false;
} else if arg == "--no-license" {
check_license = false;
} else {
if !run_check(&arg, &gir_file)? {
if !run_check(&arg, &gir_file, check_manual_traits, check_license)? {
result = false;
}
break;
}
i += 1;
}
Expand Down

0 comments on commit 8be96b3

Please sign in to comment.