From 47c9c73c4b845dde67d4aea6ef16be5cdde9e79a Mon Sep 17 00:00:00 2001 From: Ryan Geary Date: Sun, 15 Mar 2020 16:43:25 -0400 Subject: Separate Opt into separate mod --- src/choice.rs | 3 ++- src/config.rs | 29 +---------------------------- src/main.rs | 4 +++- src/opt.rs | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 src/opt.rs diff --git a/src/choice.rs b/src/choice.rs index 1b26085..9d50b67 100644 --- a/src/choice.rs +++ b/src/choice.rs @@ -80,7 +80,8 @@ impl Choice { #[cfg(test)] mod tests { - use crate::config::{Config, Opt}; + use crate::config::Config; + use crate::opt::Opt; use std::ffi::OsString; use std::io::{self, BufWriter, Write}; use structopt::StructOpt; diff --git a/src/config.rs b/src/config.rs index afca365..78771cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,36 +1,9 @@ use regex::Regex; use std::num::ParseIntError; -use std::path::PathBuf; use std::process; -use structopt::StructOpt; use crate::choice::Choice; - -#[derive(Debug, StructOpt)] -#[structopt(name = "choose", about = "`choose` sections from each line of files")] -pub struct Opt { - /// Specify field separator other than whitespace - #[structopt(short, long)] - pub field_separator: Option, - - /// Use exclusive ranges, similar to array slicing in many programming languages - #[structopt(short = "x", long)] - pub exclusive: bool, - - /// Activate debug mode - #[structopt(short, long)] - pub debug: bool, - - /// Input file - #[structopt(short, long, parse(from_os_str))] - pub input: Option, - - /// Fields to print. Either x, x:, :y, or x:y, where x and y are integers, colons indicate a - /// range, and an empty field on either side of the colon continues to the beginning or end of - /// the line. - #[structopt(required = true, min_values = 1, parse(try_from_str = Config::parse_choice))] - pub choice: Vec, -} +use crate::opt::Opt; lazy_static! { static ref PARSE_CHOICE_RE: Regex = Regex::new(r"^(\d*):(\d*)$").unwrap(); diff --git a/src/main.rs b/src/main.rs index b812462..dbefafa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,11 +7,13 @@ extern crate lazy_static; mod choice; mod config; +mod opt; mod reader; use config::Config; +use opt::Opt; fn main() { - let opt = config::Opt::from_args(); + let opt = Opt::from_args(); let config = Config::new(opt); let read = match &config.opt.input { diff --git a/src/opt.rs b/src/opt.rs new file mode 100644 index 0000000..3548127 --- /dev/null +++ b/src/opt.rs @@ -0,0 +1,32 @@ +use std::path::PathBuf; +use structopt::StructOpt; + +use crate::choice::Choice; +use crate::config::Config; + +#[derive(Debug, StructOpt)] +#[structopt(name = "choose", about = "`choose` sections from each line of files")] +pub struct Opt { + /// Specify field separator other than whitespace + #[structopt(short, long)] + pub field_separator: Option, + + /// Use exclusive ranges, similar to array slicing in many programming languages + #[structopt(short = "x", long)] + pub exclusive: bool, + + /// Activate debug mode + #[structopt(short, long)] + pub debug: bool, + + /// Input file + #[structopt(short, long, parse(from_os_str))] + pub input: Option, + + /// Fields to print. Either x, x:, :y, or x:y, where x and y are integers, colons indicate a + /// range, and an empty field on either side of the colon continues to the beginning or end of + /// the line. + #[structopt(required = true, min_values = 1, parse(try_from_str = Config::parse_choice))] + pub choice: Vec, +} + -- cgit v1.2.3