3080: More convenient run_with_output r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-02-10 14:16:42 +00:00 committed by GitHub
commit 46a474866e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 19 deletions

View file

@ -18,7 +18,7 @@ impl Cmd<'_> {
run(self.unix, self.work_dir)
}
}
pub fn run_with_output(self) -> Result<Output> {
pub fn run_with_output(self) -> Result<String> {
if cfg!(windows) {
run_with_output(self.windows, self.work_dir)
} else {
@ -34,8 +34,10 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> {
.map(|_| ())
}
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> {
do_run(cmdline, dir, &mut |_| {})
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<String> {
let output = do_run(cmdline, dir, &mut |_| {})?;
let stdout = String::from_utf8(output.stdout)?;
Ok(stdout)
}
fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> {

View file

@ -127,15 +127,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
}
.run()?;
let installed_extensions = {
let output = Cmd {
unix: &format!(r"{} --list-extensions", code_binary),
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
work_dir: ".",
}
.run_with_output()?;
String::from_utf8(output.stdout)?
};
let installed_extensions = Cmd {
unix: &format!(r"{} --list-extensions", code_binary),
windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
work_dir: ".",
}
.run_with_output()?;
if !installed_extensions.contains("rust-analyzer") {
anyhow::bail!(
@ -161,12 +158,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
fn install_server(opts: ServerOpt) -> Result<()> {
let mut old_rust = false;
if let Ok(output) = run_with_output("cargo --version", ".") {
if let Ok(stdout) = String::from_utf8(output.stdout) {
println!("{}", stdout);
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
old_rust = true;
}
if let Ok(stdout) = run_with_output("cargo --version", ".") {
println!("{}", stdout);
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
old_rust = true;
}
}

View file

@ -14,7 +14,7 @@ pub fn run_hook() -> Result<()> {
let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?;
let root = project_root();
for line in String::from_utf8(diff.stdout)?.lines() {
for line in diff.lines() {
run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;
}