From 28be2c5b07d0a466640108fad13d3501a8bd0e68 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 5 Apr 2021 01:09:06 +0200 Subject: util: make outfile configurable (or print to stdout) --- utils/src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'utils/src') diff --git a/utils/src/main.rs b/utils/src/main.rs index d49a3d7..bcd63f6 100644 --- a/utils/src/main.rs +++ b/utils/src/main.rs @@ -42,6 +42,9 @@ struct Options { /// encrypt the survey with the given password (not yet implemented) #[structopt(long, short)] password: Option>, + /// file to write the configuration to (will otherwise print to stdout) + #[structopt(long, short)] + out_file: Option } fn main () { @@ -97,7 +100,15 @@ fn main () { encrypted.as_slice() } }; - fs::write("outfile", outdata).expect("cannot write to outfile!"); + match opt.out_file { + Some(file) => fs::write(file.clone(), outdata) + .expect(&format!("cannot write to file {:?}!", file)), + None => { + let mut out = std::io::stdout(); + out.write_all(outdata).unwrap(); + out.flush().unwrap() + } + }; } } } -- cgit v1.2.3