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