Browse Source

Moved args into a separate module

develop
Drew Short 6 years ago
parent
commit
17644a44bf
  1. 45
      src/args/mod.rs
  2. 0
      src/args/parse.rs
  3. 46
      src/main.rs

45
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 <warrick@sothr.com>")
.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),
])
}

0
src/args.rs → src/args/parse.rs

46
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 <warrick@sothr.com>")
.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
);

Loading…
Cancel
Save