summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorstuebinm2021-04-05 01:09:06 +0200
committerstuebinm2021-04-05 01:09:06 +0200
commit28be2c5b07d0a466640108fad13d3501a8bd0e68 (patch)
tree3855562662a13a4f2313048091b327d7e3e79bf5 /utils
parent92f2e0267323137941645426e90d75f214e1a590 (diff)
util: make outfile configurable (or print to stdout)
Diffstat (limited to '')
-rw-r--r--utils/src/main.rs13
1 files changed, 12 insertions, 1 deletions
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<secrecy::Secret<String>>,
+ /// file to write the configuration to (will otherwise print to stdout)
+ #[structopt(long, short)]
+ out_file: Option<PathBuf>
}
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()
+ }
+ };
}
}
}