diff options
author | Vincent Ambo <mail@tazj.in> | 2023-01-18T15·31+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2023-01-18T15·44+0000 |
commit | 0ed6583edcdaac73f4ed7fb30b09d8fb95c25f9d (patch) | |
tree | c14660b8ab95f2bcea5510d00c904c2989c79c79 | |
parent | 476e312c06213e53757349a93cc7f855889bc61c (diff) |
feat(corp/data-import): let users specify output path r/5692
Change-Id: I61ad021c7a5318b099f3adc8bc6aedef65500974 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7865 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
-rw-r--r-- | corp/russian/data-import/src/main.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/corp/russian/data-import/src/main.rs b/corp/russian/data-import/src/main.rs index 70eb0a56dd28..8a76c3823e27 100644 --- a/corp/russian/data-import/src/main.rs +++ b/corp/russian/data-import/src/main.rs @@ -69,17 +69,25 @@ fn main() { .filter_level(log::LevelFilter::Info) .init(); - let input_path = env::args() - .skip(1) - .next() - .ensure("must specify the input filename as the only argument"); + let (input_path, output_path) = { + let mut args = env::args().collect::<Vec<_>>(); + + if args.len() != 3 { + bail(format!( + "usage: {} <input-file> <output-file>", + args.first().map(String::as_str).unwrap_or("data-import") + )); + } + + (args.remove(1), args.remove(1)) + }; - info!("reading from {input_path}"); + info!("reading from {input_path}; writing output to {output_path}"); let input_file = File::open(input_path).ensure("failed to open input file"); let mut parser = oc_parser::OpenCorporaParser::new(BufReader::new(input_file)); - let conn = Connection::open("out.db").ensure("failed to open DB connection"); + let conn = Connection::open(output_path).ensure("failed to open DB connection"); db_setup::initial_schema(&conn); |