From 0ed6583edcdaac73f4ed7fb30b09d8fb95c25f9d Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 18 Jan 2023 18:31:02 +0300 Subject: feat(corp/data-import): let users specify output path Change-Id: I61ad021c7a5318b099f3adc8bc6aedef65500974 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7865 Tested-by: BuildkiteCI Reviewed-by: tazjin --- corp/russian/data-import/src/main.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'corp/russian/data-import/src') 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::>(); + + if args.len() != 3 { + bail(format!( + "usage: {} ", + 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); -- cgit 1.4.1