1use std::ffi::OsString;
6use std::path::PathBuf;
7
8use clap::Parser;
9
10#[derive(Debug, Clone, Parser)]
11#[command(name = "cargo-grip4rust", version = "0.1.4")]
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
24impl Args {
25 pub fn parse_from_args<I, T>(args: I) -> Self
26 where
27 I: IntoIterator<Item = T>,
28 T: Into<OsString> + Clone,
29 {
30 Self::parse_from(args)
31 }
32
33 pub fn parse_cargo() -> Self {
34 let raw: Vec<OsString> = std::env::args_os().collect();
35 if raw.len() > 1 && raw[1].to_string_lossy() == "grip4rust" {
36 let mut filtered = vec![raw[0].clone()];
37 filtered.extend(raw.into_iter().skip(2));
38 Self::parse_from(filtered)
39 } else {
40 Self::parse()
41 }
42 }
43}