1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use crate::{args::FeatureArgs, config::Config, Result, Run};
#[cfg_attr(doc, doc = include_str!("../../doc/cargo-xtask-tidy.md"))]
#[derive(Debug, Clone, Default, clap::Args)]
#[non_exhaustive]
pub struct Tidy {
#[clap(long)]
allow_no_vcs: bool,
#[clap(long)]
allow_dirty: bool,
#[clap(long)]
allow_staged: bool,
#[clap(flatten)]
pub feature_args: FeatureArgs,
}
impl Run for Tidy {
fn run(&self, config: &Config) -> Result<()> {
self.run(config)
}
}
impl Tidy {
pub fn subcommands(&self) -> Vec<Box<dyn Run>> {
let Self {
allow_no_vcs,
allow_dirty,
allow_staged,
feature_args,
} = self;
let _ = allow_no_vcs; let _ = allow_dirty; let _ = allow_staged; let _ = feature_args.clone(); vec![
#[cfg(feature = "subcommand-fmt")]
Box::new(super::Fmt {
env_args: Default::default(),
package_args: feature_args.package_args.clone(),
extra_options: vec![],
}),
#[cfg(feature = "subcommand-clippy")]
Box::new({
let mut clippy_options = vec![];
if *allow_no_vcs {
clippy_options.push("--allow-no-vcs");
}
if *allow_dirty {
clippy_options.push("--allow-dirty");
}
if *allow_staged {
clippy_options.push("--allow-staged");
}
super::Clippy {
env_args: Default::default(),
feature_args: feature_args.clone(),
extra_options: ["--fix", "--all-targets"]
.into_iter()
.chain(clippy_options)
.map(String::from)
.collect(),
}
}),
#[cfg(feature = "subcommand-rdme")]
Box::new({
let mut rdme_options = vec![];
if *allow_dirty || *allow_staged {
rdme_options.push("--force");
}
super::Rdme {
env_args: Default::default(),
workspace_args: feature_args.package_args.workspace_args.clone(),
extra_options: rdme_options.into_iter().map(String::from).collect(),
}
}),
]
}
#[tracing::instrument(name = "tidy", skip_all, err)]
pub fn run(&self, config: &Config) -> Result<()> {
for subcommand in self.subcommands() {
subcommand.run(config)?;
}
Ok(())
}
}