From 17644a44bfd83970d94696d3cea14455a35e07bc Mon Sep 17 00:00:00 2001 From: Drew Short Date: Wed, 5 Dec 2018 19:04:45 -0600 Subject: [PATCH] Moved args into a separate module --- src/args/mod.rs | 45 +++++++++++++++++++++++++++++++++ src/{args.rs => args/parse.rs} | 0 src/main.rs | 46 ++++------------------------------ 3 files changed, 50 insertions(+), 41 deletions(-) create mode 100644 src/args/mod.rs rename src/{args.rs => args/parse.rs} (100%) diff --git a/src/args/mod.rs b/src/args/mod.rs new file mode 100644 index 0000000..7641f47 --- /dev/null +++ b/src/args/mod.rs @@ -0,0 +1,45 @@ +use clap::{App, Arg}; + +use VERSION; +use DEFAULT_HOST; +use DEFAULT_PORT_STR; +use DEFAULT_WORKERS_STR; + +pub mod parse; + +pub fn get_app() -> App<'static, 'static> { + App::new("Dynamic DNS Server") + .version(VERSION) + .author("Drew Short ") + .about("Receive DDNS requests and update associated cloudflare subdomains") + .args(&[ + Arg::with_name("config") + .short("c") + .long("config") + .value_name("PATH") + .default_value("/etc/rsddns/rsddns.yml") + .help("Set a custom configuration file path.") + .takes_value(true), + Arg::with_name("host") + .short("h") + .long("host") + .value_name("HOST") + .default_value(&DEFAULT_HOST) + .help("The address the server listens on.") + .takes_value(true), + Arg::with_name("port") + .short("p") + .long("port") + .value_name("PORT") + .default_value(&DEFAULT_PORT_STR) + .help("The port to run the server on.") + .takes_value(true), + Arg::with_name("workers") + .short("w") + .long("workers") + .value_name("NUMBER") + .default_value(&DEFAULT_WORKERS_STR) + .help("The number of workers to serve requests with.") + .takes_value(true), + ]) +} \ No newline at end of file diff --git a/src/args.rs b/src/args/parse.rs similarity index 100% rename from src/args.rs rename to src/args/parse.rs diff --git a/src/main.rs b/src/main.rs index c15b687..eeb95a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,6 @@ extern crate serde; extern crate serde_derive; extern crate serde_yaml; -use clap::{App, Arg}; - mod args; mod config; mod server; @@ -37,41 +35,7 @@ fn main() { } env_logger::init(); - let args = App::new("Dynamic DNS Server") - .version(VERSION) - .author("Drew Short ") - .about("Receive DDNS requests and update associated cloudflare subdomains") - .args(&[ - Arg::with_name("config") - .short("c") - .long("config") - .value_name("PATH") - .default_value("/etc/rsddns/rsddns.yml") - .help("Set a custom configuration file path.") - .takes_value(true), - Arg::with_name("host") - .short("h") - .long("host") - .value_name("HOST") - .default_value(&DEFAULT_HOST) - .help("The address the server listens on.") - .takes_value(true), - Arg::with_name("port") - .short("p") - .long("port") - .value_name("PORT") - .default_value(&DEFAULT_PORT_STR) - .help("The port to run the server on.") - .takes_value(true), - Arg::with_name("workers") - .short("w") - .long("workers") - .value_name("NUMBER") - .default_value(&DEFAULT_WORKERS_STR) - .help("The number of workers to serve requests with.") - .takes_value(true), - ]) - .get_matches(); + let args = args::get_app().get_matches(); let config_path: &str = args.value_of("config").unwrap_or("/etc/rsddns/rsddns.yml"); let config = match config::load::read(config_path) { @@ -85,12 +49,12 @@ fn main() { } }; - let host = args::get_host(&args, &config, DEFAULT_HOST); - let port = args::get_port(&args, &config, DEFAULT_PORT); - let workers = args::get_workers(&args, &config, *DEFAULT_WORKERS); + let host = args::parse::get_host(&args, &config, DEFAULT_HOST); + let port = args::parse::get_port(&args, &config, DEFAULT_PORT); + let workers = args::parse::get_workers(&args, &config, *DEFAULT_WORKERS); info!( - "Starting server on {}:{} with workers={} and config {}", + "Starting server on {}:{} with workers={} and config \"{}\"", host, port, workers, config_path );