use std::path::PathBuf;
use crate::cli::Cli;
#[derive(Clone, Debug)]
pub struct AnalysisOptions {
pub path: PathBuf,
pub jobs: usize,
pub short_days: u32,
pub long_days: u32,
pub include_generated: bool,
pub all_files: bool,
pub exclude: Vec<String>,
pub extensions: Vec<String>,
pub include_prefix: Vec<String>,
pub exclude_prefix: Vec<String>,
pub no_cargo: bool,
}
impl AnalysisOptions {
pub fn new(path: impl Into<PathBuf>) -> Self {
Self {
path: path.into(),
..Self::default()
}
}
}
impl Default for AnalysisOptions {
fn default() -> Self {
Self {
path: PathBuf::from("."),
jobs: default_jobs(),
short_days: 7,
long_days: 30,
include_generated: false,
all_files: false,
exclude: Vec::new(),
extensions: Vec::new(),
include_prefix: Vec::new(),
exclude_prefix: Vec::new(),
no_cargo: false,
}
}
}
impl From<&Cli> for AnalysisOptions {
fn from(cli: &Cli) -> Self {
Self {
path: cli.path.clone(),
jobs: cli.jobs,
short_days: cli.short_days,
long_days: cli.long_days,
include_generated: cli.source.include_generated,
all_files: cli.source.all_files,
exclude: cli.source.exclude.clone(),
extensions: cli.source.extensions.clone(),
include_prefix: cli.source.include_prefix.clone(),
exclude_prefix: cli.source.exclude_prefix.clone(),
no_cargo: cli.source.no_cargo,
}
}
}
pub(crate) fn default_jobs() -> usize {
std::thread::available_parallelism().map_or(1, |count| count.get().min(8))
}