From deaca6ce619226614b9e1b770590515a7b80d9a0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 13 Mar 2022 13:35:36 +0100 Subject: main(): Accept input YAML from standard input Either with a "-" argument or no file argument. --- src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 5e06bb2..77092fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,9 +41,22 @@ fn main() { table_name, input_file, } => { + let input_file = match &input_file { + Some(f) => f, + None => "-", + }; + let mut dbconn = rusqlite::Connection::open(database).unwrap(); - let text_data = std::fs::read_to_string(input_file.unwrap()).unwrap(); + let mut text_data; + if input_file == "-" { + use std::io::Read; + + text_data = String::new(); + std::io::stdin().read_to_string(&mut text_data).unwrap(); + } else { + text_data = std::fs::read_to_string(input_file).unwrap(); + } let mut yaml_data = yaml::YamlLoader::load_from_str(&text_data).unwrap(); -- cgit v1.2.3