diff --git a/Cargo.toml b/Cargo.toml index 88c062c..a5d9e86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ indoc = "0.3.5" md5 = "0.7.0" nom = "5.1.1" serde = { version = "1.0", features = ["derive"] } +structopt = "0.3" toml = "0.5" yaserde = { git = "https://github.com/media-io/yaserde.git" } yaserde_derive = { git = "https://github.com/media-io/yaserde.git" } diff --git a/src/cmdline.rs b/src/cmdline.rs new file mode 100644 index 0000000..5c07494 --- /dev/null +++ b/src/cmdline.rs @@ -0,0 +1,11 @@ +use std::path::PathBuf; +use structopt::StructOpt; + +/// A standards-compliant bridge to Reolink IP cameras +#[derive(StructOpt, Debug)] +#[structopt(name = "neolink")] +pub struct Opt { + /// main configuration file + #[structopt(short, long, parse(from_os_str))] + pub config: PathBuf, +} diff --git a/src/main.rs b/src/main.rs index 20ec7f7..bdbb25e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,16 @@ mod bc; mod bc_protocol; mod config; +mod cmdline; use bc_protocol::BcCamera; use config::{Config, CameraConfig}; +use cmdline::Opt; use crossbeam_utils::thread; use err_derive::Error; -use std::env::args; use std::fs; use std::net::TcpListener; +use structopt::StructOpt; #[derive(Debug, Error)] pub enum Error { @@ -21,8 +23,8 @@ pub enum Error { } fn main() -> Result<(), Error> { - let config_path = args().nth(1).expect("A config file must be supplied on the command line"); - let config: Config = toml::from_str(&fs::read_to_string(config_path)?)?; + let opt = Opt::from_args(); + let config: Config = toml::from_str(&fs::read_to_string(opt.config)?)?; thread::scope(|s| { for camera in config.cameras {