diff options
author | Ryan Geary <rtgnj42@gmail.com> | 2019-09-02 00:27:56 -0400 |
---|---|---|
committer | Ryan Geary <rtgnj42@gmail.com> | 2019-09-02 00:27:56 -0400 |
commit | b1baf8f9b3d3eb69981ab22cfbdf7594579f9ef7 (patch) | |
tree | eb8c26eec844ee858e11bc7558ba385f6f850677 | |
parent | 76a6d3e53b8f3f79dd212fe61d979d94824d4f0e (diff) |
Start parsing command line and reading input file
-rw-r--r-- | src/main.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e505d6b --- /dev/null +++ b/src/main.rs @@ -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!"); +} |