Rewrite rust (#38)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

Co-authored-by: kjuulh <contact@kjuulh.io>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/octopush/pulls/38
This commit is contained in:
2022-11-27 11:21:35 +00:00
parent 0d6e8bc4a0
commit 991861db99
445 changed files with 53358 additions and 2568 deletions

View File

@@ -0,0 +1,50 @@
use std::{path::PathBuf, process::Stdio};
use eyre::Context;
use tokio::io::{AsyncBufReadExt, BufReader};
pub async fn execute_shell(cmd: String, path: Option<PathBuf>) -> eyre::Result<()> {
let mut command = tokio::process::Command::new("sh");
let command = command.arg("-c");
let command = if let Some(path) = path {
command.current_dir(path)
} else {
command
};
let command = command.arg(format!("{}", cmd));
let command = command.stdout(Stdio::piped());
let mut child = command.spawn()?;
let stdout = child
.stdout
.take()
.ok_or(eyre::anyhow!("could not take stdout of command"))?;
let mut reader = BufReader::new(stdout).lines();
tokio::spawn(async move {
let status = child
.wait()
.await
.context(eyre::anyhow!("child process encountered an error"))
.unwrap();
if !status.success() {
tracing::error!(
cmd,
status = status.to_string(),
"child program encountered an error"
);
}
});
while let Some(line) = reader.next_line().await? {
tracing::trace!("{}", line)
}
Ok(())
}