Skip to content

Commit 46a4748

Browse files
bors[bot]matklad
andauthored
Merge #3080
3080: More convenient run_with_output r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 33df947 + 1b6acc3 commit 46a4748

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

xtask/src/cmd.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Cmd<'_> {
1818
run(self.unix, self.work_dir)
1919
}
2020
}
21-
pub fn run_with_output(self) -> Result<Output> {
21+
pub fn run_with_output(self) -> Result<String> {
2222
if cfg!(windows) {
2323
run_with_output(self.windows, self.work_dir)
2424
} else {
@@ -34,8 +34,10 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> {
3434
.map(|_| ())
3535
}
3636

37-
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> {
38-
do_run(cmdline, dir, &mut |_| {})
37+
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<String> {
38+
let output = do_run(cmdline, dir, &mut |_| {})?;
39+
let stdout = String::from_utf8(output.stdout)?;
40+
Ok(stdout)
3941
}
4042

4143
fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> {

xtask/src/install.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
127127
}
128128
.run()?;
129129

130-
let installed_extensions = {
131-
let output = Cmd {
132-
unix: &format!(r"{} --list-extensions", code_binary),
133-
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
134-
work_dir: ".",
135-
}
136-
.run_with_output()?;
137-
String::from_utf8(output.stdout)?
138-
};
130+
let installed_extensions = Cmd {
131+
unix: &format!(r"{} --list-extensions", code_binary),
132+
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
133+
work_dir: ".",
134+
}
135+
.run_with_output()?;
139136

140137
if !installed_extensions.contains("rust-analyzer") {
141138
anyhow::bail!(
@@ -161,12 +158,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
161158

162159
fn install_server(opts: ServerOpt) -> Result<()> {
163160
let mut old_rust = false;
164-
if let Ok(output) = run_with_output("cargo --version", ".") {
165-
if let Ok(stdout) = String::from_utf8(output.stdout) {
166-
println!("{}", stdout);
167-
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
168-
old_rust = true;
169-
}
161+
if let Ok(stdout) = run_with_output("cargo --version", ".") {
162+
println!("{}", stdout);
163+
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
164+
old_rust = true;
170165
}
171166
}
172167

xtask/src/pre_commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn run_hook() -> Result<()> {
1414
let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?;
1515

1616
let root = project_root();
17-
for line in String::from_utf8(diff.stdout)?.lines() {
17+
for line in diff.lines() {
1818
run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;
1919
}
2020

0 commit comments

Comments
 (0)