Navigation Menu

Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mmou committed May 6, 2020
1 parent 8708131 commit d0aef37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion audit.toml.example
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/audit.rs
Expand Up @@ -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")]
Expand Down
24 changes: 14 additions & 10 deletions src/presenter.rs
Expand Up @@ -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<Dependency>,

/// Track warning kinds
/// Keep track of the warning kinds that correspond to deny-warnings options
deny_warning_kinds: Set<warning::Kind>,

/// Output configuration
Expand Down Expand Up @@ -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),
);
}
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down

0 comments on commit d0aef37

Please sign in to comment.