cargo_fixit/util/
cli.rs

1use clap::Parser;
2
3#[derive(Debug, Parser)]
4pub struct CheckFlags {
5    /// Package(s) to fix
6    #[arg(short, long, value_name = "SPEC", help_heading = "Package Selection")]
7    package: Vec<String>,
8
9    /// Fix all packages in the workspace
10    #[arg(long, help_heading = "Package Selection")]
11    workspace: bool,
12
13    /// Exclude packages from the fixes
14    #[arg(long, value_name = "SPEC", help_heading = "Package Selection")]
15    exclude: Vec<String>,
16
17    /// Alias for --workspace (deprecated)
18    #[arg(long, help_heading = "Package Selection")]
19    all: bool,
20
21    /// Fix only this package's library
22    #[arg(long, help_heading = "Target Selection")]
23    lib: bool,
24
25    /// Fix all binaries
26    #[arg(long, help_heading = "Target Selection")]
27    bins: bool,
28
29    /// Fix only the specified binary
30    #[arg(long, value_name = "NAME", help_heading = "Target Selection")]
31    bin: Option<String>,
32
33    /// Fix all examples
34    #[arg(long, help_heading = "Target Selection")]
35    examples: bool,
36
37    /// Fix only the specified binary
38    #[arg(long, value_name = "NAME", help_heading = "Target Selection")]
39    example: Option<String>,
40
41    /// Fix all tests
42    #[arg(long, help_heading = "Target Selection")]
43    tests: bool,
44
45    /// Fix only the specified test
46    #[arg(long, value_name = "NAME", help_heading = "Target Selection")]
47    test: Option<String>,
48
49    /// Fix all benches
50    #[arg(long, help_heading = "Target Selection")]
51    benches: bool,
52
53    /// Fix only the specified bench
54    #[arg(long, value_name = "NAME", help_heading = "Target Selection")]
55    bench: Option<String>,
56
57    /// Fix all targets
58    #[arg(long, help_heading = "Target Selection")]
59    all_targets: bool,
60
61    /// Space or comma separated list of features to activate
62    #[arg(
63        short = 'F',
64        long,
65        value_name = "FEATURES",
66        help_heading = "Feature Selection"
67    )]
68    features: Vec<String>,
69
70    /// Activate all available features
71    #[arg(long, help_heading = "Feature Selection")]
72    all_features: bool,
73
74    /// Do not activate the `default` feature
75    #[arg(long, help_heading = "Feature Selection")]
76    no_default_features: bool,
77
78    /// Unstable (nightly-only) flags
79    #[arg(short = 'Z', value_name = "FLAG")]
80    unstable_flags: Vec<String>,
81}
82
83impl CheckFlags {
84    pub fn to_flags(&self) -> Vec<String> {
85        let mut out = Vec::new();
86
87        for spec in self.package.clone() {
88            out.push("--package".to_owned());
89            out.push(spec);
90        }
91        if self.workspace {
92            out.push("--workspace".to_owned());
93        }
94        for spec in self.exclude.clone() {
95            out.push("--exclude".to_owned());
96            out.push(spec);
97        }
98        if self.all {
99            out.push("--all".to_owned());
100        }
101
102        if self.lib {
103            out.push("--lib".to_owned());
104        }
105
106        if self.bins {
107            out.push("--bins".to_owned());
108        }
109        if let Some(b) = self.bin.clone() {
110            out.push("--bin".to_owned());
111            out.push(b);
112        }
113
114        if self.examples {
115            out.push("--examples".to_owned());
116        }
117        if let Some(b) = self.example.clone() {
118            out.push("--example".to_owned());
119            out.push(b);
120        }
121
122        if self.tests {
123            out.push("--tests".to_owned());
124        }
125        if let Some(b) = self.test.clone() {
126            out.push("--test".to_owned());
127            out.push(b);
128        }
129
130        if self.benches {
131            out.push("--benches".to_owned());
132        }
133        if let Some(b) = self.bench.clone() {
134            out.push("--bench".to_owned());
135            out.push(b);
136        }
137
138        if self.all_targets {
139            out.push("--all-targets".to_owned());
140        }
141
142        for i in self.features.clone() {
143            out.push("--features".to_owned());
144            out.push(i);
145        }
146        if self.all_features {
147            out.push("--all-features".to_owned());
148        }
149        if self.no_default_features {
150            out.push("--no-default-features".to_owned());
151        }
152
153        for i in self.unstable_flags.clone() {
154            out.push("-Z".to_owned());
155            out.push(i);
156        }
157
158        out
159    }
160}