-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split runner module and add verify path
- Loading branch information
Showing
3 changed files
with
95 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::{ | ||
fs::File, | ||
path::PathBuf, | ||
process::{Command, Stdio}, | ||
}; | ||
|
||
use anyhow::{Context as _, Result}; | ||
|
||
pub struct Runner { | ||
cmd: String, | ||
args: Vec<String>, | ||
stdout: Stdio, | ||
stderr: Stdio, | ||
} | ||
|
||
impl Runner { | ||
/// Create a new runner with the given command. | ||
pub fn new(cmd: impl Into<String>) -> Self { | ||
Self { | ||
cmd: cmd.into(), | ||
args: vec![], | ||
stdout: Stdio::piped(), | ||
stderr: Stdio::piped(), | ||
} | ||
} | ||
|
||
/// Add arguments to the command. | ||
pub fn args(mut self, args: &[&str]) -> Self { | ||
self.args.extend(args.iter().map(|s| s.to_string())); | ||
self | ||
} | ||
|
||
/// Create the file specified by `output_filepath` and set it as the stdout | ||
/// and stderr of the command. | ||
pub fn out(mut self, output_filepath: impl Into<PathBuf>) -> Result<Self> { | ||
let out = File::create(output_filepath.into())?; | ||
let err = out.try_clone()?; | ||
self.stdout = Stdio::from(out); | ||
self.stderr = Stdio::from(err); | ||
Ok(self) | ||
} | ||
|
||
/// Run the command. | ||
pub fn run(self) -> Result<()> { | ||
let output = Command::new(&self.cmd) | ||
Check failure on line 45 in scripts/runner.rs GitHub Actions / clippy
Check failure on line 45 in scripts/runner.rs GitHub Actions / udeps
|
||
.args(&self.args) | ||
.stdout(self.stdout) | ||
.stderr(self.stderr) | ||
.output() | ||
.context(format!("couldn't exec `{}`", &self.cmd))?; | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
mod outdated; | ||
mod prove_rpc; | ||
mod runner; | ||
|
||
use anyhow::Result; | ||
use clap::Parser; | ||
|