Start parsing command line and reading input file

This commit is contained in:
Ryan Geary 2019-09-02 00:27:56 -04:00
parent 76a6d3e53b
commit b1baf8f9b3

41
src/main.rs Normal file
View file

@ -0,0 +1,41 @@
use std::fs::File;
use std::io::{self, BufRead, BufReader, Read};
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "choose", about = "`choose` sections from each line of files")]
struct Opt {
/// Specify field separator other than whitespace
#[structopt(short, long, default_value = "")]
field_separator: String,
/// Use inclusive ranges
#[structopt(short, long)]
inclusive: bool,
/// Activate debug mode
#[structopt(short, long)]
debug: bool,
/// Input file
#[structopt(parse(from_os_str))]
input: Option<PathBuf>,
}
fn main() {
let opt = Opt::from_args();
let read = match &opt.input {
Some(f) => Box::new(File::open(f).expect("Could not open file")) as Box<Read>,
None => Box::new(io::stdin()) as Box<Read>,
};
let buf = BufReader::new(read);
for line in buf.lines() {
println!("{}", line.unwrap());
}
println!("Hello, world!");
}