diff --git a/src/cmdline.rs b/src/cmdline.rs index 1b4d3a6..1fb1f18 100644 --- a/src/cmdline.rs +++ b/src/cmdline.rs @@ -3,10 +3,14 @@ use structopt::{clap::AppSettings, StructOpt}; /// A standards-compliant bridge to Reolink IP cameras #[derive(StructOpt, Debug)] -#[structopt(name = "neolink", setting(AppSettings::ArgRequiredElseHelp))] +#[structopt( + name = "neolink", + setting(AppSettings::ArgRequiredElseHelp), + setting(AppSettings::UnifiedHelpMessage) +)] pub struct Opt { - #[structopt(short, long, parse(from_os_str))] - pub config: PathBuf, + #[structopt(short, long, global(true), parse(from_os_str))] + pub config: Option, #[structopt(subcommand)] pub cmd: Option, } diff --git a/src/main.rs b/src/main.rs index 6f033ad..ff6a0fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,15 +36,16 @@ fn main() -> Result<()> { let opt = Opt::from_args(); + let conf_path = opt.config.context("Must supply --config file")?; let config: Config = toml::from_str( - &fs::read_to_string(&opt.config) - .with_context(|| format!("Failed to read {:?}", &opt.config))?, + &fs::read_to_string(&conf_path) + .with_context(|| format!("Failed to read {:?}", conf_path))?, ) - .with_context(|| format!("Failed to parse the {:?} config file", &opt.config))?; + .with_context(|| format!("Failed to parse the {:?} config file", conf_path))?; config .validate() - .with_context(|| format!("Failed to validate the {:?} config file", &opt.config))?; + .with_context(|| format!("Failed to validate the {:?} config file", conf_path))?; match opt.cmd { None => {