summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-11-26 12:20:32 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-11-26 12:23:40 +0000
commit9052490a6085879c41d91b53ed06c4f360bef2a2 (patch)
tree6f7552dfc8b4531da7da1b3de0c27ab720dfe629
parente0b2386e753c654ca09c1a65e455be8f7338bfc7 (diff)
downloadrsyarn-9052490a6085879c41d91b53ed06c4f360bef2a2.tar.bz2
Prologue and Epilogue should be read in, not output verbatim
-rw-r--r--src/main.rs14
-rw-r--r--src/opt.rs4
-rw-r--r--src/runner.rs4
3 files changed, 15 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 0881be8..7dadf47 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
use std::fs;
use std::io;
use std::io::Write;
+use std::path::Path;
use std::process::exit;
use std::time::Instant;
@@ -274,6 +275,13 @@ fn run_yarn(args: &opt::YarnArgs) -> err::YarnResult<()> {
Ok(())
}
+fn load_file(fname: impl AsRef<Path>) -> Vec<u8> {
+ match std::fs::read(&fname) {
+ Err(e) => panic!("Unable to read {}: {}", fname.as_ref().display(), e),
+ Ok(b) => b,
+ }
+}
+
fn main() {
let m = cli::get_app().get_matches();
if m.is_present("completions") {
@@ -296,13 +304,13 @@ fn main() {
args.verbose = false;
}
if m.is_present("prologue") {
- for pfile in m.values_of("prologue").unwrap() {
- args.prologue.push(pfile.to_string());
+ for pfile in m.values_of_os("prologue").unwrap() {
+ args.prologue.push(load_file(&pfile));
}
}
if m.is_present("epilogue") {
for pfile in m.values_of("epilogue").unwrap() {
- args.epilogue.push(pfile.to_string());
+ args.epilogue.push(load_file(&pfile));
}
}
if m.is_present("run") {
diff --git a/src/opt.rs b/src/opt.rs
index 9bcc7e6..a319c92 100644
--- a/src/opt.rs
+++ b/src/opt.rs
@@ -9,8 +9,8 @@ pub struct YarnArgs {
pub pretend: bool,
pub quiet: bool,
pub verbose: bool,
- pub prologue: Vec<String>,
- pub epilogue: Vec<String>,
+ pub prologue: Vec<Vec<u8>>,
+ pub epilogue: Vec<Vec<u8>>,
pub run: Vec<String>,
pub tempdir: String,
pub env: Vec<(String, String)>,
diff --git a/src/runner.rs b/src/runner.rs
index 20e6afa..ba92a93 100644
--- a/src/runner.rs
+++ b/src/runner.rs
@@ -191,14 +191,14 @@ impl<'a> YarnRunner<'a> {
{
let mut scriptfile = File::create(&scriptfile_)?;
for prel in &self.args.prologue {
- scriptfile.write_all(&prel.as_bytes())?;
+ scriptfile.write_all(&prel)?;
scriptfile.write("\n".as_bytes())?;
}
for line in &imp.content {
scriptfile.write_all(&line.as_bytes())?;
}
for epil in &self.args.epilogue {
- scriptfile.write_all(&epil.as_bytes())?;
+ scriptfile.write_all(&epil)?;
scriptfile.write("\n".as_bytes())?;
}
}