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 <tazjin@tvl.su>
This commit is contained in:
Vincent Ambo 2023-01-18 18:31:02 +03:00 committed by tazjin
parent 476e312c06
commit 0ed6583edc

View file

@ -69,17 +69,25 @@ fn main() {
.filter_level(log::LevelFilter::Info) .filter_level(log::LevelFilter::Info)
.init(); .init();
let input_path = env::args() let (input_path, output_path) = {
.skip(1) let mut args = env::args().collect::<Vec<_>>();
.next()
.ensure("must specify the input filename as the only argument");
info!("reading from {input_path}"); 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}; writing output to {output_path}");
let input_file = File::open(input_path).ensure("failed to open input file"); 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 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); db_setup::initial_schema(&conn);