Skip to content

Commit

Permalink
Upgrade to clap 4 - will require valid UTF-8 --in and --out
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Sep 25, 2023
1 parent 77ec2ef commit 1f0457c
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 123 deletions.
107 changes: 59 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions imageflow_helpers/src/process_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::process::{Command, Output};
pub struct CaptureTo{
args: Vec<String>,
executable: PathBuf,
basepath: String,
basepath: PathBuf,
include_binary: IncludeBinary
}

Expand All @@ -28,7 +28,7 @@ pub enum IncludeBinary{

impl CaptureTo{

pub fn create(capture_to: &str, bin_location: Option<PathBuf>, args: Vec<String>, include_binary: IncludeBinary) -> CaptureTo{
pub fn create(capture_to: &PathBuf, bin_location: Option<PathBuf>, args: Vec<String>, include_binary: IncludeBinary) -> CaptureTo{
let executable= bin_location.unwrap_or_else(|| std::env::current_exe().expect("For CaptureTo to work, we need to know the binary's location. env::current_exe failed"));

CaptureTo{
Expand All @@ -40,7 +40,10 @@ impl CaptureTo{

}
fn write_bytes(&self, suffix: &str, bytes: &[u8]) -> std::result::Result<(),std::io::Error>{
let filename = format!("{}_{}", self.basepath, suffix);

let mut filename = self.basepath.as_os_str().to_owned();
filename.push("_");
filename.push(suffix);
let mut file = BufWriter::new(File::create(&filename)?);
file.write_all(bytes).and_then(|_| Ok(()))
}
Expand All @@ -50,7 +53,9 @@ impl CaptureTo{
cmd.args(args).env("RUST_BACKTRACE","1");
let output = cmd.output()?;

let filename = format!("{}_{}", self.basepath, suffix);
let mut filename = self.basepath.as_os_str().to_owned();
filename.push("_");
filename.push(suffix);
let mut file = BufWriter::new(File::create(&filename)?);

let header = format!("{:?} exited with status {:?}\nSTDERR:\n", cmd, output.status);
Expand Down Expand Up @@ -103,7 +108,10 @@ impl CaptureTo{
self.write_bytes("artifact_url.txt", s.as_bytes()).unwrap();
}else if or_copy{
//Otherwise copy the binary
let target_path = format!("{}_{}", self.basepath, self.executable.as_path().file_name().unwrap().to_str().unwrap());
let mut target_path = self.basepath.as_os_str().to_owned();
target_path.push("_");
target_path.push(self.executable.as_path().file_name().unwrap());

std::fs::copy(&self.executable, &target_path).unwrap();
}

Expand Down
24 changes: 19 additions & 5 deletions imageflow_helpers/src/process_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ use super::timeywimey::Utc;
pub struct ProcOutput {
exit_code: Option<i32>,
r: Option<Output>,
empty: Vec<u8>
empty: Vec<u8>,
invocation: String
}

impl ProcOutput {
pub fn from(r: Output) -> ProcOutput {
ProcOutput { exit_code: r.status.code(),r: Some(r), empty: Vec::new() }
pub fn from(r: Output, invocation: String) -> ProcOutput {
ProcOutput { exit_code: r.status.code(),r: Some(r), empty: Vec::new(),invocation }
}
pub fn from_code(code: Option<i32>) -> ProcOutput {
ProcOutput { r: None, exit_code: code, empty: Vec::new() }
ProcOutput { r: None, exit_code: code, empty: Vec::new(), invocation: String::new() }
}
// fn status_code(&self) -> Option<i32> {
// match *self {
Expand Down Expand Up @@ -136,6 +137,18 @@ impl ProcOutput {
self.stderr_str());
self
}

pub fn print_to_err(&self) -> &ProcOutput {
eprintln!("{}", self.invocation);
eprintln!("Exited with {:?}", self.status_code());
eprintln!("===== STDERR =====");
eprint!("{}",self.stderr_str());
eprintln!("===== STDERR =====");
eprintln!("===== STDOUT =====");
eprint!("{}",self.stdout_str());
eprintln!("===== STDOUT =====");
self
}
}


Expand Down Expand Up @@ -249,6 +262,7 @@ impl ProcTestContext {
let mut cmd = Command::new(exe);
cmd.args(args_vec.as_slice()).current_dir(dir).env("RUST_BACKTRACE", "1");

let invocation = format!("{:?}", cmd);

cmd.stderr(Stdio::piped()).stdout(Stdio::piped());

Expand Down Expand Up @@ -295,7 +309,7 @@ impl ProcTestContext {
}
}

ProcOutput::from(output)
ProcOutput::from(output, invocation)
}


Expand Down
2 changes: 1 addition & 1 deletion imageflow_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
imageflow_core = { path = "../imageflow_core", version = "*" }
imageflow_types = { path = "../imageflow_types", version = "*" }
libc = "0.2"
clap = "3"
clap = "4"
time = "0.3"
threadpool = "1"
serde = "1"
Expand Down
8 changes: 4 additions & 4 deletions imageflow_tool/src/cmd_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ extern crate serde;

use std::collections::HashMap;
use std::fs::File;
use std::path::{Path};
use std::path::{Path, PathBuf};
use std::io::{Write, Read, BufWriter};
use crate::fc::{JsonResponse, ErrorCategory};
use crate::fc::errors::CategorizedError;

pub enum JobSource {
JsonFile(String),
JsonFile(PathBuf),
// NamedDemo(String),
Ir4QueryString(String)
}
Expand Down Expand Up @@ -145,7 +145,7 @@ impl CmdBuild {
let mut data = Vec::new();
let mut f = match File::open(&path) {
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
return Err(CmdError::JsonRecipeNotFound(path.to_owned()));
return Err(CmdError::JsonRecipeNotFound(path.to_string_lossy().into()));
}
other => other,
}?;
Expand Down Expand Up @@ -399,7 +399,7 @@ impl CmdBuild {
}
///
/// Write the JSON response (if present) to the given file or STDOUT
pub fn write_response_maybe(&self, response_file: Option<&str>, allow_stdout: bool) -> std::io::Result<()> {
pub fn write_response_maybe(&self, response_file: Option<&PathBuf>, allow_stdout: bool) -> std::io::Result<()> {
if self.response.is_some() {

if let Some(filename) = response_file {
Expand Down
Loading

0 comments on commit 1f0457c

Please sign in to comment.