argf/
lib.rs

1use std::io;
2use std::io::Read;
3use std::iter::Iterator;
4
5pub fn from_arguments() -> Box<io::Read> {
6
7    return from_slice(&std::env::args().collect::<Vec<String>>());
8}
9
10pub fn from_slice<I>(input: &[I]) -> Box<io::Read>
11    where I: AsRef<str>
12{
13    let mut chain: Box<Read> = Box::new(std::io::empty().chain(std::io::empty()));
14    for reader in input.iter().map(|p| to_reader(p.as_ref())) {
15        chain = Box::new(chain.chain(reader));
16    }
17    chain
18}
19
20fn to_reader<'a>(path: &'a str) -> Box<io::Read> {
21    if path == "-" {
22        Box::new(io::stdin())
23    } else {
24        Box::new(std::fs::File::open(path).unwrap())
25    }
26}