#[macro_use] extern crate clap;
extern crate libsniff;
extern crate colored;
extern crate regex;
use libsniff::prelude::*;
use clap::App;
use colored::*;
#[allow(unknown_lints)]
#[allow(cyclomatic_complexity)]
fn main() {
#[cfg(feature = "english")]
let yaml = load_yaml!("options-en.yml");
#[cfg(feature = "francais")]
let yaml = load_yaml!("options-fr.yml");
#[cfg(feature = "deutsch")]
let yaml = load_yaml!("options-de.yml");
let matches = App::from_yaml(yaml).version(crate_version!()).get_matches();
if let Some(command) = matches.subcommand_matches("fat") {
let min_bytes = match threshold(command.value_of("threshold")) {
Some(t) => t,
_ => 1048576,
};
let depth = get_depth(command.value_of("depth"));
let print_files = command.is_present("files");
let force_parallel = command.is_present("parallel");
let nproc = if force_parallel { get_processors() } else { 0 };
let regex = command.value_of("excludes");
let init_dir = get_dir(command.value_of("dir"));
let v = match regex {
Some(r) => read_all(&init_dir, force_parallel, 0, Some(depth), None, Some(&check_regex(r)), nproc, &None, false, false),
_ => read_all(&init_dir, force_parallel, 0, Some(depth), None, None, nproc, &None, false, false),
};
let mut v_filtered = v.filtered(depth, Some(min_bytes), !print_files);
v_filtered.display_tree(init_dir);
}
else if let Some(command) = matches.subcommand_matches("all") {
let min_bytes = threshold(command.value_of("threshold"));
let depth = get_depth(command.value_of("depth"));
let force_parallel = command.is_present("parallel");
let nproc = if force_parallel { get_processors() } else { 0 };
let regex = command.value_of("excludes");
let print_files = command.is_present("files");
let init_dir = get_dir(command.value_of("dir"));
let v = match regex {
Some(r) => read_all(&init_dir, force_parallel, 0, Some(depth), None, Some(&check_regex(r)), nproc, &None, false, false),
_ => read_all(&init_dir, force_parallel, 0, Some(depth), None, None, nproc, &None, false, false),
};
let mut v_filtered = v.filtered(depth, min_bytes, !print_files);
v_filtered.display_tree(init_dir);
}
else if let Some(command) = matches.subcommand_matches("ar") {
let min_bytes = threshold(command.value_of("threshold"));
let depth = get_depth(command.value_of("depth"));
let force_parallel = command.is_present("parallel");
let num_int = get_num(command.value_of("count"));
let should_sort = command.is_present("sort");
let print_files = command.is_present("files");
let artifacts = command.value_of("regex");
let no_gitignore = command.is_present("gitignore");
let init_dir = get_dir(command.value_of("dir"));
let nproc = 0;
let v = if let Some(r) = artifacts {
let re = check_regex(r);
let excludes = get_excludes(command.value_of("excludes"));
read_all(&init_dir, force_parallel, 0, Some(depth), Some(&re), Some(&excludes), nproc, &None, !no_gitignore, true)
}
else {
let excludes = get_excludes(command.value_of("excludes"));
read_all(&init_dir, force_parallel, 0, Some(depth), None, Some(&excludes), nproc, &None, !no_gitignore, true)
};
let mut v_processed = if should_sort {
v.sort(Some(num_int), depth, min_bytes, !print_files)
}
else {
v.filtered(depth, min_bytes, !print_files)
};
v_processed.display_tree(init_dir);
}
else if let Some(command) = matches.subcommand_matches("sort") {
let min_bytes = threshold(command.value_of("threshold"));
let num_int = get_num(command.value_of("count"));
let depth = get_depth(command.value_of("depth"));
let force_parallel = command.is_present("parallel");
let nproc = if force_parallel { get_processors() } else { 0 };
let print_files = command.is_present("files");
let init_dir = get_dir(command.value_of("dir"));
let regex =
if let Some(n) = command.value_of("excludes") {
Some(n)
}
else {
None
};
let v = match regex {
Some(r) => read_all(&init_dir, force_parallel, 0, Some(depth), None, Some(&check_regex(r)), nproc, &None, false, false),
_ => read_all(&init_dir, force_parallel, 0, Some(depth), None, None, nproc, &None, false, false),
};
let mut v_sorted = v.sort(Some(num_int), depth, min_bytes, !print_files);
v_sorted.display_tree(init_dir);
}
else {
eprintln!("{}: Command not recognized. Try 'sniff --help' if you're stuck.", "Error".red());
}
}