Fixes issue with ohmyzsh returning 80 on a successful run (#570)

This commit is contained in:
Seung-Li Maeda
2020-12-01 19:56:12 -08:00
committed by GitHub
parent 4f3bdcad86
commit f9116dd0f3
3 changed files with 34 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
//! Utilities for command execution
use crate::error::TopgradeError;
use crate::utils::Check;
use crate::utils::{Check, CheckWithCodes};
use anyhow::Result;
use log::{debug, trace};
use std::ffi::{OsStr, OsString};
@@ -166,6 +166,13 @@ impl Executor {
pub fn check_run(&mut self) -> Result<()> {
self.spawn()?.wait()?.check()
}
/// An extension of `check_run` that allows you to set a sequence of codes
/// that can indicate success of a script
#[allow(dead_code)]
pub fn check_run_with_codes(&mut self, codes: &[i32]) -> Result<()> {
self.spawn()?.wait()?.check_with_codes(codes)
}
}
pub enum ExecutorOutput {
@@ -232,6 +239,15 @@ impl Check for ExecutorExitStatus {
}
}
impl CheckWithCodes for ExecutorExitStatus {
fn check_with_codes(self, codes: &[i32]) -> Result<()> {
match self {
ExecutorExitStatus::Wet(e) => e.check_with_codes(codes),
ExecutorExitStatus::Dry => Ok(()),
}
}
}
/// Extension methods for `std::process::Command`
pub trait CommandExt {
/// Run the command, wait for it to complete, check the return code and decode the output as UTF-8.