diff --git a/src/config.rs b/src/config.rs index 4d37664..e56942d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,16 @@ use std::path::{Path, PathBuf}; +#[derive(Debug, StructOpt)] pub struct Config { + /// The root configuration directory for dip. This argument is required. + #[structopt(short = "d", long = "root", parse(from_os_str))] pub root: PathBuf, + /// A string containing the address to bind to. This defaults to "0.0.0.0:5000". + #[structopt(short = "b", long = "bind", default_value = "0.0.0.0:5000")] pub bind: String, + /// If a hook is specified here, it will be triggered manually exactly once and then the + /// program will exit rather than running as a server. + #[structopt(short = "h", long = "hook")] pub hook: Option, } diff --git a/src/lib.rs b/src/lib.rs index f080ece..23fb59c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,8 @@ extern crate serde_json; #[macro_use] extern crate lazy_static; extern crate notify; +#[macro_use] +extern crate structopt; extern crate regex; extern crate toml; extern crate walkdir; diff --git a/src/main.rs b/src/main.rs index 27290ba..88a3586 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,32 +1,12 @@ -#[macro_use] -extern crate structopt; extern crate dip; extern crate failure; - -use std::path::PathBuf; +extern crate structopt; use dip::Config; use failure::Error; use structopt::StructOpt; -#[derive(Debug, StructOpt)] -struct Opt { - /// The root configuration directory for dip. This argument is required. - #[structopt(short = "d", long = "root", parse(from_os_str))] - root: PathBuf, - /// A string containing the address to bind to. This defaults to "0.0.0.0:5000". - #[structopt(short = "b", long = "bind")] - bind: Option, - /// If a hook is specified here, it will be triggered manually exactly once and then the - /// program will exit rather than running as a server. - #[structopt(short = "h", long = "hook")] - hook: Option, -} - fn main() -> Result<(), Error> { - let opt = Opt::from_args(); - println!("{:?}", opt); - - let config = Config::new(opt.root).bind(opt.bind).hook(opt.hook); + let config = Config::from_args(); dip::run(&config) }