rustfmt
This commit is contained in:
parent
7e3efbed5c
commit
fc51f8128a
3 changed files with 23 additions and 15 deletions
14
src/main.rs
14
src/main.rs
|
@ -88,7 +88,12 @@ fn main() {
|
|||
debug!("Checking files regardless of extensions");
|
||||
}
|
||||
|
||||
let entries = scan_directory(&args.dirs, extensions.as_ref(), excludes.as_ref(), &args.get_scan_opts());
|
||||
let entries = scan_directory(
|
||||
&args.dirs,
|
||||
extensions.as_ref(),
|
||||
excludes.as_ref(),
|
||||
&args.get_scan_opts(),
|
||||
);
|
||||
|
||||
if entries.is_none() {
|
||||
// no need to log anything for fatal errors - fif will already have printed something obvious like
|
||||
|
@ -285,7 +290,12 @@ fn scan_from_walkdir(entries: &[DirEntry]) -> Vec<Result<Findings, ScanError>> {
|
|||
|
||||
/// Scans a given directory with [`WalkDir`], filters with [`wanted_file`], checks for errors, and returns a vector of
|
||||
/// [DirEntry]s.
|
||||
fn scan_directory(dirs: &Path, exts: Option<&Vec<&str>>, exclude: Option<&Vec<&str>>, scan_opts: &ScanOpts) -> Option<Vec<DirEntry>> {
|
||||
fn scan_directory(
|
||||
dirs: &Path,
|
||||
exts: Option<&Vec<&str>>,
|
||||
exclude: Option<&Vec<&str>>,
|
||||
scan_opts: &ScanOpts,
|
||||
) -> Option<Vec<DirEntry>> {
|
||||
let stepper = WalkDir::new(dirs).follow_links(scan_opts.follow_symlinks).into_iter();
|
||||
let mut probably_fatal_error = false;
|
||||
let entries: Vec<DirEntry> = stepper
|
||||
|
|
|
@ -52,12 +52,7 @@ pub struct Parameters {
|
|||
|
||||
/// Don't scan files with these extensions (comma-separated list).
|
||||
/// This option takes preference over files specified with -e or -E.
|
||||
#[clap(
|
||||
short = 'x',
|
||||
long,
|
||||
use_delimiter = true,
|
||||
require_delimiter = true,
|
||||
)]
|
||||
#[clap(short = 'x', long, use_delimiter = true, require_delimiter = true)]
|
||||
pub exclude: Option<Vec<StringType>>,
|
||||
|
||||
/// Don't skip hidden files and directories.
|
||||
|
@ -136,7 +131,10 @@ impl Parameters {
|
|||
}
|
||||
|
||||
pub fn excluded_extensions(&self) -> Option<Vec<&str>> {
|
||||
self.exclude.as_ref().map(|exclude| exclude.iter().map(|ext| ext.as_str()).collect())
|
||||
self
|
||||
.exclude
|
||||
.as_ref()
|
||||
.map(|exclude| exclude.iter().map(|ext| ext.as_str()).collect())
|
||||
}
|
||||
|
||||
pub const fn get_scan_opts(&self) -> ScanOpts {
|
||||
|
|
|
@ -174,7 +174,8 @@ fn argument_parsing() {
|
|||
let args: Parameters = Parameters::parse_from(vec!["fif", "-f", "-E", "images"]);
|
||||
|
||||
// check if "jpg" is in the list of extensions to be scanned
|
||||
assert!(args
|
||||
assert!(
|
||||
args
|
||||
.extensions()
|
||||
.expect("args.extensions() should be Some(_)!")
|
||||
.contains(&"jpg"),
|
||||
|
@ -205,7 +206,7 @@ fn argument_parsing() {
|
|||
#[test]
|
||||
/// Ensure exclude overrides `-e` and `-E`.
|
||||
fn exclude_overrides() {
|
||||
use crate::parameters::{Parameters};
|
||||
use crate::parameters::Parameters;
|
||||
use clap::Clap;
|
||||
|
||||
// pass `-E images`, which includes many image extensions, and `-x jpg,png`, which should remove "jpg" and "png" from
|
||||
|
@ -231,7 +232,6 @@ fn exclude_overrides() {
|
|||
assert!(extensions.contains(&"jkl"));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
/// Ensure that badly formed command line arguments are rejected.
|
||||
fn rejects_bad_args() {
|
||||
|
|
Loading…
Reference in a new issue