Skip to main content

grip/
args.rs

1// Copyright 2026 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the MIT License
3// SPDX-License-Identifier: MIT
4
5use std::ffi::OsString;
6use std::path::PathBuf;
7
8use clap::Parser;
9
10#[derive(Debug, Clone, Parser)]
11#[command(name = "cargo-grip4rust", version = "0.2.0")]
12#[command(about = "Measure Rust testability")]
13pub struct Args {
14    #[arg(default_value = ".")]
15    pub path: PathBuf,
16
17    #[arg(long)]
18    pub json: bool,
19
20    #[arg(long, alias = "min-score")]
21    pub threshold: Option<u32>,
22
23    #[arg(long)]
24    pub verbose: bool,
25}
26
27impl Args {
28    pub fn parse_from_args<I, T>(args: I) -> Self
29    where
30        I: IntoIterator<Item = T>,
31        T: Into<OsString> + Clone,
32    {
33        Self::parse_from(args)
34    }
35
36    pub fn parse_cargo() -> Self {
37        let raw: Vec<OsString> = std::env::args_os().collect();
38        if raw.len() > 1 && raw[1].to_string_lossy() == "grip4rust" {
39            let mut filtered = vec![raw[0].clone()];
40            filtered.extend(raw.into_iter().skip(2));
41            Self::parse_from(filtered)
42        } else {
43            Self::parse()
44        }
45    }
46}