xtask/tasks/fmt/
verify_flowey.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::Xtask;
5use crate::shell::XtaskShell;
6use anyhow::Context;
7use clap::Parser;
8
9#[derive(Parser)]
10#[clap(about = "Ensure all flowey pipelines are up to date")]
11pub struct VerifyFlowey {
12    /// Fix any out-of-date pipelines
13    #[clap(long)]
14    pub fix: bool,
15}
16
17impl VerifyFlowey {
18    pub fn new(fix: bool) -> Self {
19        Self { fix }
20    }
21}
22
23impl Xtask for VerifyFlowey {
24    fn run(self, ctx: crate::XtaskCtx) -> anyhow::Result<()> {
25        // need to go through all this rigamarole because `cargo --quiet
26        // xflowey regen` doesn't do what you'd hope it'd do
27        let cmd = {
28            let data = fs_err::read_to_string(ctx.root.join(".cargo/config.toml"))?;
29            let mut cmd = None;
30            for ln in data.lines() {
31                if let Some(ln) = ln.trim().strip_prefix(r#"xflowey = ""#) {
32                    let alias = ln
33                        .strip_suffix('"')
34                        .context("invalid .cargo/config.toml")?
35                        .split(' ')
36                        .map(|s| s.to_owned())
37                        .collect::<Vec<_>>();
38                    cmd = Some(alias);
39                }
40            }
41            cmd.context("could not find `xflowey` alias in .cargo/config.toml")?
42        };
43
44        let check = (!self.fix).then_some("--check");
45
46        let sh = XtaskShell::new()?;
47        sh.cmd("cargo")
48            .arg("--quiet")
49            .args(&cmd)
50            .args(["regen", "--quiet"])
51            .args(check)
52            .quiet()
53            .run()?;
54
55        Ok(())
56    }
57}