move the structopt struct into the lib

This commit is contained in:
Michael 2018-08-16 15:10:22 +00:00
parent 3977c172db
commit 6b6087c4e9
3 changed files with 12 additions and 22 deletions

View file

@ -1,8 +1,16 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
#[derive(Debug, StructOpt)]
pub struct Config { 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, 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, 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<String>, pub hook: Option<String>,
} }

View file

@ -10,6 +10,8 @@ extern crate serde_json;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
extern crate notify; extern crate notify;
#[macro_use]
extern crate structopt;
extern crate regex; extern crate regex;
extern crate toml; extern crate toml;
extern crate walkdir; extern crate walkdir;

View file

@ -1,32 +1,12 @@
#[macro_use]
extern crate structopt;
extern crate dip; extern crate dip;
extern crate failure; extern crate failure;
extern crate structopt;
use std::path::PathBuf;
use dip::Config; use dip::Config;
use failure::Error; use failure::Error;
use structopt::StructOpt; 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<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")]
hook: Option<String>,
}
fn main() -> Result<(), Error> { fn main() -> Result<(), Error> {
let opt = Opt::from_args(); let config = Config::from_args();
println!("{:?}", opt);
let config = Config::new(opt.root).bind(opt.bind).hook(opt.hook);
dip::run(&config) dip::run(&config)
} }