From bdd83128ebdc0e6f6f031dc4a515689ade715940 Mon Sep 17 00:00:00 2001 From: Matthias Endler Date: Fri, 14 Aug 2020 11:43:45 +0200 Subject: [PATCH] Refactor options --- src/main.rs | 45 +++++---------------------------------------- src/options.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 40 deletions(-) create mode 100644 src/options.rs diff --git a/src/main.rs b/src/main.rs index 6b85619..6111b86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,54 +2,19 @@ extern crate log; use anyhow::Result; +use futures::future::join_all; +use gumdrop::Options; use regex::RegexSet; +use reqwest::Url; use std::{collections::HashSet, env}; mod checker; mod collector; mod extract; +mod options; use checker::{CheckStatus, Checker}; -use futures::future::join_all; - -use gumdrop::Options; -use reqwest::Url; - -#[derive(Debug, Options)] -struct LycheeOptions { - #[options(free, help = "Input files")] - inputs: Vec, - - #[options(help = "show help")] - help: bool, - - #[options(help = "Verbose program output")] - verbose: bool, - - #[options(help = "Maximum number of allowed redirects", default = "10")] - max_redirects: usize, - - #[options( - help = "Number of threads to utilize (defaults to number of cores available to the system" - )] - threads: Option, - - #[options(help = "User agent", default = "curl/7.71.1")] - user_agent: String, - - #[options( - help = "Proceed for server connections considered insecure (invalid TLS)", - default = "false" - )] - insecure: bool, - - #[options(help = "Only test links with given scheme (e.g. https)")] - scheme: Option, - - // Accumulate all exclusions in a vector - #[options(help = "Exclude URLs from checking (supports regex)")] - exclude: Vec, -} +use options::LycheeOptions; fn main() -> Result<()> { pretty_env_logger::init(); diff --git a/src/options.rs b/src/options.rs new file mode 100644 index 0000000..9bc6fea --- /dev/null +++ b/src/options.rs @@ -0,0 +1,37 @@ +use gumdrop::Options; + +#[derive(Debug, Options)] +pub(crate) struct LycheeOptions { + #[options(free, help = "Input files")] + pub inputs: Vec, + + #[options(help = "show help")] + pub help: bool, + + #[options(help = "Verbose program output")] + pub verbose: bool, + + #[options(help = "Maximum number of allowed redirects", default = "10")] + pub max_redirects: usize, + + #[options( + help = "Number of threads to utilize (defaults to number of cores available to the system" + )] + pub threads: Option, + + #[options(help = "User agent", default = "curl/7.71.1")] + pub user_agent: String, + + #[options( + help = "Proceed for server connections considered insecure (invalid TLS)", + default = "false" + )] + pub insecure: bool, + + #[options(help = "Only test links with given scheme (e.g. https)")] + pub scheme: Option, + + // Accumulate all exclusions in a vector + #[options(help = "Exclude URLs from checking (supports regex)")] + pub exclude: Vec, +}