From d0aef3782cc2acffa0c8d2d551f62f2fc5d0b366 Mon Sep 17 00:00:00 2001 From: M Mou Date: Sun, 15 Mar 2020 23:08:10 -0700 Subject: [PATCH] clean up --- audit.toml.example | 2 +- src/commands/audit.rs | 2 +- src/presenter.rs | 24 ++++++++++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/audit.toml.example b/audit.toml.example index 5c4561d8..259fa7b2 100644 --- a/audit.toml.example +++ b/audit.toml.example @@ -16,7 +16,7 @@ stale = false # Allow stale advisory DB (i.e. no commits for 90 days, default: f # Output Configuration [output] -deny_warnings = ["unmaintained", "other"] # exit on error if any warnings are found +deny_warnings = ["unmaintained", "other"] # exit on error if unmaintained or other warnings are found format = "terminal" # "terminal" (human readable report) or "json" quiet = false # Only print information on error show_tree = true # Show inverse dependency trees along with advisories (default: true) diff --git a/src/commands/audit.rs b/src/commands/audit.rs index 196550de..6166244b 100644 --- a/src/commands/audit.rs +++ b/src/commands/audit.rs @@ -19,7 +19,7 @@ use std::{path::PathBuf, process::exit}; use self::fix::FixCommand; /// The `cargo audit` subcommand -#[derive(Default, Debug, Options, Command)] +#[derive(Command, Default, Debug, Options)] pub struct AuditCommand { /// Optional subcommand (used for `cargo audit fix`) #[cfg(feature = "fix")] diff --git a/src/presenter.rs b/src/presenter.rs index bea3c377..2dc7625a 100644 --- a/src/presenter.rs +++ b/src/presenter.rs @@ -25,11 +25,11 @@ use std::{ /// Vulnerability information presenter #[derive(Clone, Debug)] pub struct Presenter { - /// Track packages we've displayed once so we don't show the same dep tree + /// Keep track packages we've displayed once so we don't show the same dep tree // TODO(tarcieri): group advisories about the same package? displayed_packages: Set, - /// Track warning kinds + /// Keep track of the warning kinds that correspond to deny-warnings options deny_warning_kinds: Set, /// Output configuration @@ -146,7 +146,12 @@ impl Presenter { } for advisory in self_advisories { - self.print_advisory_warning(&advisory.metadata); + self.print_advisory_warning( + &advisory.metadata, + self.config + .deny_warnings + .contains(&DenyWarningOption::Other), + ); } } @@ -247,7 +252,10 @@ impl Presenter { match &warning.kind { warning::Kind::Informational | warning::Kind::Unmaintained => { if let Some(advisory) = &warning.advisory { - self.print_advisory_warning(advisory) + self.print_advisory_warning( + advisory, + self.deny_warning_kinds.contains(&warning.kind), + ) } else { warn!("warning missing advisory: {:?}", warning); } @@ -272,12 +280,8 @@ impl Presenter { } /// Print a warning about a particular advisory - fn print_advisory_warning(&self, metadata: &rustsec::advisory::Metadata) { - let color = self.warning_color( - self.config - .deny_warnings - .contains(&DenyWarningOption::Other), - ); + fn print_advisory_warning(&self, metadata: &rustsec::advisory::Metadata, deny_warning: bool) { + let color = self.warning_color(deny_warning); println!(); self.print_attr(color, "Crate: ", &metadata.package);