Skip to content

Commit

Permalink
added new silentjson output variant
Browse files Browse the repository at this point in the history
  • Loading branch information
epi052 committed Nov 9, 2023
1 parent 69b79f1 commit c6ffb6b
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/config/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ pub enum OutputLevel {

/// silent scan, only print urls (used to be --quiet in versions 1.x.x)
Silent,

/// silent scan, but with JSON output
SilentJSON,
}

/// implement a default for OutputLevel
Expand All @@ -111,14 +114,22 @@ impl Default for OutputLevel {
}

/// given the current settings for quiet and silent, determine output_level (DRY helper)
pub fn determine_output_level(quiet: bool, silent: bool) -> OutputLevel {
pub fn determine_output_level(quiet: bool, silent: bool, json: bool) -> OutputLevel {
if quiet && silent {
// user COULD have both as true in config file, take the more quiet of the two
OutputLevel::Silent
if json {
OutputLevel::SilentJSON
} else {
OutputLevel::Silent
}
} else if quiet {
OutputLevel::Quiet
} else if silent {
OutputLevel::Silent
if json {
OutputLevel::SilentJSON
} else {
OutputLevel::Silent
}
} else {
OutputLevel::Default
}
Expand Down Expand Up @@ -166,16 +177,28 @@ mod tests {
#[test]
/// test determine_output_level returns higher of the two levels if both given values are true
fn determine_output_level_returns_correct_results() {
let mut level = determine_output_level(true, true);
let mut level = determine_output_level(true, true, false);
assert_eq!(level, OutputLevel::Silent);

level = determine_output_level(false, true);
level = determine_output_level(false, true, false);
assert_eq!(level, OutputLevel::Silent);

level = determine_output_level(false, false);
let mut level = determine_output_level(true, true, true);
assert_eq!(level, OutputLevel::SilentJSON);

level = determine_output_level(false, true, true);
assert_eq!(level, OutputLevel::SilentJSON);

level = determine_output_level(false, false, false);
assert_eq!(level, OutputLevel::Default);

level = determine_output_level(true, false, false);
assert_eq!(level, OutputLevel::Quiet);

level = determine_output_level(false, false, true);
assert_eq!(level, OutputLevel::Default);

level = determine_output_level(true, false);
level = determine_output_level(true, false, true);
assert_eq!(level, OutputLevel::Quiet);
}

Expand Down

0 comments on commit c6ffb6b

Please sign in to comment.