summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorRyan Geary <rtgnj42@gmail.com>2019-10-10 21:24:07 -0400
committerRyan Geary <rtgnj42@gmail.com>2019-10-10 21:24:07 -0400
commitc204f99444d70d74969ac081fe6b36830b62e21a (patch)
treecf7aec8342a4dbd111e514dd358ebea6e27c9526 /src/main.rs
parentf722cbcbbb61ba46c5d6e63d543a834c65a51751 (diff)
Reorganize massivelyv0.1.2
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index d6c7c50..1050950 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,15 +1,16 @@
-use regex::Regex;
use std::fs::File;
use std::io::{self, BufRead, BufReader, Read, Write};
-use std::process;
use structopt::StructOpt;
mod choice;
+mod config;
+use config::Config;
fn main() {
- let opt = choice::Opt::from_args();
+ let opt = config::Opt::from_args();
+ let config = Config::new(opt);
- let read = match &opt.input {
+ let read = match &config.opt.input {
Some(f) => Box::new(File::open(f).expect("Could not open file")) as Box<dyn Read>,
None => Box::new(io::stdin()) as Box<dyn Read>,
};
@@ -20,22 +21,12 @@ fn main() {
let lock = stdout.lock();
let mut handle = io::BufWriter::new(lock);
- let re = Regex::new(match &opt.field_separator {
- Some(s) => s,
- None => "[[:space:]]",
- })
- .unwrap_or_else(|e| {
- eprintln!("Failed to compile regular expression: {}", e);
- // Exit code of 1 means failed to compile field_separator regex
- process::exit(1);
- });
-
let lines = buf.lines();
for line in lines {
match line {
Ok(l) => {
- for choice in &opt.choice {
- choice.print_choice(&l, &opt, &re, &mut handle);
+ for choice in &config.opt.choice {
+ choice.print_choice(&l, &config, &mut handle);
}
writeln!(handle, "");
}