Skip to content

Commit

Permalink
Do not show [testing] packages by default
Browse files Browse the repository at this point in the history
Fixes #34
  • Loading branch information
ilpianista committed Feb 29, 2020
1 parent 74a490c commit b92d054
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
1 change: 1 addition & 0 deletions completions/zsh/_arch-audit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typeset -A opt_args
_arguments -s -S \
"(-h --help)"{-h,--help}"[Prints help information]" \
"(*-q --quiet)"{"*-q","--quiet"}"[Show only vulnerable package names and their versions]" \
"(-t --show-testing)"{-t,--show-testing}"[Show packages which are in the [testing] repos. See https://wiki.archlinux.org/index.php/Official_repositories#Testing_repositories]" \
"(-u --upgradable)"{-u,--upgradable}"[Show only packages that have already been fixed]" \
"(-V --version)"{-V,--version}"[Prints version information]" \
"(-b --dbpath)"{-b,--dbpath}"[Set an alternate database location]:dbpath:_files -/" \
Expand Down
6 changes: 6 additions & 0 deletions doc/arch-audit.1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Prints help information.
Show only vulnerable package names and their versions.
.RE
.PP
\fI-t, --show-testing\fR
.RS 4
Show packages which are in the [testing] repos. See
https://wiki.archlinux.org/index.php/Official_repositories#Testing_repositories
.RE
.PP
\fI-u, --upgradable\fR
.RS 4
Show only packages that have already been fixed.
Expand Down
4 changes: 4 additions & 0 deletions src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ args:
long: quiet
multiple: true
help: Show only vulnerable package names and their versions
- testing:
short: t
long: show-testing
help: Show packages which are in the [testing] repos. See https://wiki.archlinux.org/index.php/Official_repositories#Testing_repositories
- upgradable:
short: u
long: upgradable
Expand Down
61 changes: 44 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct Options {
format: Option<String>,
quiet: u64,
upgradable_only: bool,
show_testing: bool,
}

impl Default for Options {
Expand All @@ -41,6 +42,7 @@ impl Default for Options {
format: None,
quiet: 0,
upgradable_only: false,
show_testing: false,
}
}
}
Expand All @@ -60,6 +62,7 @@ fn main() {
},
quiet: args.occurrences_of("quiet"),
upgradable_only: args.is_present("upgradable"),
show_testing: args.is_present("testing"),
};

let mut avgs = String::new();
Expand Down Expand Up @@ -391,10 +394,10 @@ fn print_avgs(options: &Options, avgs: &BTreeMap<String, avg::AVG>) {
} else {
match options.format {
Some(ref f) => {
print_avg_formatted(&mut t, pkg, avg, v, f);
print_avg_formatted(&mut t, pkg, avg, v, options.show_testing, f);
}
None => {
print_avg_colored(&mut t, pkg, avg, v);
print_avg_colored(&mut t, pkg, avg, v, options.show_testing);
}
}
}
Expand All @@ -408,10 +411,23 @@ fn print_avgs(options: &Options, avgs: &BTreeMap<String, avg::AVG>) {
} else {
match options.format {
Some(ref f) => {
print_avg_formatted(&mut t, pkg, avg, &String::new(), f);
print_avg_formatted(
&mut t,
pkg,
avg,
&String::new(),
options.show_testing,
f,
);
}
None => {
print_avg_colored(&mut t, pkg, avg, &String::new());
print_avg_colored(
&mut t,
pkg,
avg,
&String::new(),
options.show_testing,
);
}
}

Expand All @@ -429,27 +445,33 @@ fn print_avg_colored(
pkg: &String,
avg: &avg::AVG,
version: &String,
show_testing: bool,
) {
// Bold package
write!(t, "Package ").expect("term::write failed");
write_with_colours(t, pkg, None, Some(term::Attr::Bold));
// Normal "is affected by {issues}"
write!(t, " is affected by {}. ", avg.issues.join(", ")).expect("term::write failed");
// Colored severit
write_with_colours(t, avg.severity.to_string().as_str(), Some(avg.severity.to_color()), None);
write_with_colours(
t,
avg.severity.to_string().as_str(),
Some(avg.severity.to_color()),
None,
);
write!(t, "!").expect("term::write failed");

if !version.is_empty() {
if avg.status == enums::Status::Testing {
// Print: Update to {} from the testing repos!"
write!(t, " Update to ").expect("term::write failed");
write_with_colours(t, version, Some(term::color::GREEN), Some(term::Attr::Bold));
write!(t, " from the testing repos!").expect("term::write failed");
} else if avg.status == enums::Status::Fixed {
if avg.status == enums::Status::Fixed {
// Print: Update to {}!
write!(t, " Update to ").expect("term::write failed");
write_with_colours(t, version, Some(term::color::GREEN), Some(term::Attr::Bold));
write!(t, "!").expect("term::write failed");
} else if avg.status == enums::Status::Testing && show_testing {
// Print: Update to {} from the testing repos!"
write!(t, " Update to ").expect("term::write failed");
write_with_colours(t, version, Some(term::color::GREEN), Some(term::Attr::Bold));
write!(t, " from the testing repos!").expect("term::write failed");
}
}
}
Expand All @@ -460,6 +482,7 @@ fn print_avg_formatted(
pkg: &String,
avg: &avg::AVG,
version: &String,
show_testing: bool,
f: &String,
) {
let mut chars = f.chars().peekable();
Expand All @@ -478,12 +501,16 @@ fn print_avg_formatted(
}
Some('v') => {
if !version.is_empty() {
write_with_colours(
t,
version,
Some(term::color::GREEN),
Some(term::Attr::Bold),
);
if avg.status == enums::Status::Fixed
|| (avg.status == enums::Status::Testing && show_testing)
{
write_with_colours(
t,
version,
Some(term::color::GREEN),
Some(term::Attr::Bold),
);
}
}
chars.next();
}
Expand Down

0 comments on commit b92d054

Please sign in to comment.