xtask/
shell.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Wrapper around [`xshell::Shell`] that centralizes the `clippy::disallowed_methods`
5//! allow to a single place, since xtask is not a flowey node and legitimately
6//! needs to spawn subprocesses.
7
8/// Thin wrapper around [`xshell::Shell`] for use in xtask code.
9pub struct XtaskShell(xshell::Shell);
10
11impl XtaskShell {
12    /// Create a new shell for spawning subprocesses.
13    #[expect(
14        clippy::disallowed_methods,
15        reason = "xtask runs outside of a flowey runtime context and needs to spawn subprocesses"
16    )]
17    pub fn new() -> anyhow::Result<Self> {
18        Ok(Self(xshell::Shell::new()?))
19    }
20
21    /// Build a command with `program` as the executable.
22    ///
23    /// Returns an [`xshell::Cmd`] builder; chain `.arg()`/`.args()`/`.run()`/
24    /// `.output()` etc. on the result.
25    pub fn cmd(&self, program: impl AsRef<std::path::Path>) -> xshell::Cmd<'_> {
26        self.0.cmd(program)
27    }
28
29    /// Read the value of an environment variable.
30    pub fn var(&self, key: &str) -> Result<String, xshell::Error> {
31        self.0.var(key)
32    }
33
34    /// Set an environment variable for commands spawned from this shell.
35    pub fn set_var(&self, key: impl AsRef<std::ffi::OsStr>, val: impl AsRef<std::ffi::OsStr>) {
36        self.0.set_var(key, val)
37    }
38}