Skip to content

Commit

Permalink
add an editor format
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Nov 20, 2020
1 parent 2c3974f commit 5a09cf1
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/main.rs
Expand Up @@ -67,9 +67,10 @@ enum Mode {
Check,
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
enum Format {
Human,
Editor,
JSON,
}

Expand All @@ -79,6 +80,7 @@ impl std::str::FromStr for Format {
fn from_str(input: &str) -> Result<Format, BadFormat> {
match input {
"human" => Ok(Format::Human),
"editor" => Ok(Format::Editor),
"json" => Ok(Format::JSON),
_ => Err(BadFormat {}),
}
Expand Down Expand Up @@ -174,23 +176,23 @@ fn run(opts: Options) -> Result<i32> {
Ok(1)
}
}
Format::Human => {
_ => {
let all_in_config =
!results.is_empty() && results.iter().all(|item| item.error_is_in_config());

for result in &results {
println!("{}", result);
}

if all_in_config {
println!(
"\nIt looks like you removed some forbidden imports. Good job! To update the config\nand remove this error, just run me with the `update` command!"
);
Ok(1)
} else if !results.is_empty() {
println!(
"\nIf these are too much to handle right now (or you intended to import a forbidden\nmodule), please run me with the `update` command!"
);
if opts.format == Format::Human {
if all_in_config {
println!( "\nIt looks like you removed some forbidden imports. Good job! To update the config\nand remove this error, just run me with the `update` command!" );
} else if !results.is_empty() {
println!( "\nIf these are too much to handle right now (or you intended to import a forbidden\nmodule), please run me with the `update` command!" );
}
}

if !results.is_empty() {
Ok(1)
} else {
Ok(0)
Expand Down

0 comments on commit 5a09cf1

Please sign in to comment.