Skip to main content

crap4rust/invocation/
config.rs

1// Copyright 2026 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the MIT License
3// SPDX-License-Identifier: MIT
4
5use std::path::PathBuf;
6
7use crate::invocation::cli::Args;
8use crate::reporting::output_format::OutputFormat;
9
10#[derive(Debug, Clone)]
11pub struct Config {
12    pub coverage_path: Option<PathBuf>,
13    pub manifest_path: Option<PathBuf>,
14    pub packages: Vec<String>,
15    pub features: Option<String>,
16    pub all_features: bool,
17    pub no_default_features: bool,
18    pub include_test_targets: bool,
19    pub exclude_paths: Vec<String>,
20    pub threshold: f64,
21    pub warn_threshold: f64,
22    pub project_threshold: f64,
23    pub strict: bool,
24    pub warn_only: bool,
25    pub output_format: OutputFormat,
26}
27
28impl Config {
29    #[must_use]
30    pub fn from_args(args: Args) -> Self {
31        Self {
32            coverage_path: args.coverage,
33            manifest_path: args.manifest_path,
34            packages: args.package,
35            features: args.features,
36            all_features: args.all_features,
37            no_default_features: args.no_default_features,
38            include_test_targets: args.include_test_targets,
39            exclude_paths: args.exclude_path,
40            threshold: args.threshold,
41            warn_threshold: args.warn_threshold,
42            project_threshold: args.project_threshold,
43            strict: args.strict,
44            warn_only: args.warn_only,
45            output_format: args.output_format,
46        }
47    }
48
49    #[must_use]
50    pub fn fails(&self, crappy_functions: usize, crappy_percent: f64) -> bool {
51        if self.strict {
52            crappy_functions > 0
53        } else {
54            crappy_percent > self.project_threshold
55        }
56    }
57}