summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Geary <rtgnj42@gmail.com>2020-03-15 16:43:25 -0400
committerRyan Geary <rtgnj42@gmail.com>2020-03-15 19:40:41 -0400
commit47c9c73c4b845dde67d4aea6ef16be5cdde9e79a (patch)
tree4285f66de998cd747d9ee34df3161de2ea9120f0
parentf87a3f16585eea8a0b545b9a77c9865cfc8aaccf (diff)
Separate Opt into separate mod
-rw-r--r--src/choice.rs3
-rw-r--r--src/config.rs29
-rw-r--r--src/main.rs4
-rw-r--r--src/opt.rs32
4 files changed, 38 insertions, 30 deletions
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<String>,
-
- /// 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<PathBuf>,
-
- /// 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<Choice>,
-}
+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<String>,
+
+ /// 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<PathBuf>,
+
+ /// 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<Choice>,
+}
+