Skip to content

Commit d0c268a

Browse files
committed
Support reading from stdin
1 parent 5656182 commit d0c268a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::{Read, Write, stdout};
1+
use std::io::{Read, Write, BufReader, BufRead, stdin, stdout};
22
use std::fs::{File, OpenOptions};
33
use std::path::Path;
44
use std::env;
@@ -160,7 +160,14 @@ fn add_table<'a>(rowpath: &str, outfile: Option<&str>, filemode: &str, skip: Opt
160160

161161
fn main() -> std::io::Result<()> {
162162
let args: Vec<_> = env::args().collect();
163-
if args.len() != 3 {
163+
let bufread: Box<dyn BufRead>;
164+
if args.len() == 2 {
165+
bufread = Box::new(BufReader::new(stdin()));
166+
}
167+
else if args.len() == 3 {
168+
bufread = Box::new(BufReader::new(File::open(&args[2])?));
169+
}
170+
else {
164171
eprintln!("usage: {} <configfile> <xmlfile>", args[0]);
165172
return Ok(());
166173
}
@@ -172,7 +179,7 @@ fn main() -> std::io::Result<()> {
172179
};
173180

174181
let mut reader;
175-
reader = Reader::from_file(&args[2]).unwrap();
182+
reader = Reader::from_reader(bufread);
176183
reader.trim_text(true)
177184
.expand_empty_elements(true);
178185

0 commit comments

Comments
 (0)