⬆️ xshell

This commit is contained in:
Aleksey Kladov 2022-03-13 21:20:51 +00:00
parent 5e85158706
commit 56e43c34e7
14 changed files with 247 additions and 212 deletions

View file

@ -11,7 +11,7 @@ use std::{
path::{Path, PathBuf},
};
use xshell::{cmd, pushenv};
use xshell::{cmd, Shell};
pub fn list_rust_files(dir: &Path) -> Vec<PathBuf> {
let mut res = list_files(dir);
@ -133,8 +133,8 @@ impl fmt::Display for Location {
}
}
fn ensure_rustfmt() {
let version = cmd!("rustfmt --version").read().unwrap_or_default();
fn ensure_rustfmt(sh: &Shell) {
let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
if !version.contains("stable") {
panic!(
"Failed to run rustfmt from toolchain 'stable'. \
@ -144,10 +144,11 @@ fn ensure_rustfmt() {
}
pub fn reformat(text: String) -> String {
let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
ensure_rustfmt();
let sh = Shell::new().unwrap();
sh.set_var("RUSTUP_TOOLCHAIN", "stable");
ensure_rustfmt(&sh);
let rustfmt_toml = project_root().join("rustfmt.toml");
let mut stdout = cmd!("rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
let mut stdout = cmd!(sh, "rustfmt --config-path {rustfmt_toml} --config fn_single_line=true")
.stdin(text)
.read()
.unwrap();