Skip to main content

crap4rust/
cli.rs

1// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the MIT License or Apache License, Version 2.0
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use std::path::PathBuf;
6
7use clap::Parser;
8
9#[derive(Debug, Clone, Parser)]
10#[command(name = "crap4rust")]
11#[command(about = "Compute CRAP scores for Rust functions")]
12pub struct Args {
13    #[arg(long)]
14    pub coverage: Option<PathBuf>,
15    #[arg(long)]
16    pub manifest_path: Option<PathBuf>,
17    #[arg(long)]
18    pub package: Vec<String>,
19    #[arg(long)]
20    pub features: Option<String>,
21    #[arg(long, default_value_t = false)]
22    pub all_features: bool,
23    #[arg(long, default_value_t = false)]
24    pub no_default_features: bool,
25    #[arg(long, default_value_t = false)]
26    pub include_test_targets: bool,
27    #[arg(long)]
28    pub exclude_path: Vec<String>,
29    #[arg(long, default_value_t = 30.0)]
30    pub threshold: f64,
31    #[arg(long, default_value_t = 5.0)]
32    pub project_threshold: f64,
33    #[arg(long, default_value_t = false)]
34    pub strict: bool,
35    #[arg(long, default_value_t = false)]
36    pub warn_only: bool,
37}
38
39impl Args {
40    pub fn parse_args() -> Self {
41        Self::parse()
42    }
43
44    pub fn parse_from_args<I, T>(args: I) -> Self
45    where
46        I: IntoIterator<Item = T>,
47        T: Into<std::ffi::OsString> + Clone,
48    {
49        Self::parse_from(args)
50    }
51}