Allow missing subcommand line specification
This commit is contained in:
2 files changed
+23
-8
No files matched your search
+6
-3
@@ -1,11 +1,14 @@
|
||||
use structopt::StructOpt;
|
||||
use std::path::PathBuf;
|
||||
use structopt::{clap::AppSettings, StructOpt};
|
||||
|
||||
/// A standards-compliant bridge to Reolink IP cameras
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "neolink")]
|
||||
#[structopt(name = "neolink", setting(AppSettings::ArgRequiredElseHelp))]
|
||||
pub struct Opt {
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
pub config: Option<PathBuf>,
|
||||
#[structopt(subcommand)]
|
||||
pub cmd: Command,
|
||||
pub cmd: Option<Command>,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
|
||||
+17
-5
@@ -32,17 +32,29 @@ fn main() -> Result<(), Error> {
|
||||
|
||||
let opt = Opt::from_args();
|
||||
|
||||
match opt.cmd {
|
||||
Command::Rtsp(opts) => {
|
||||
match (opt.cmd, opt.config) {
|
||||
(None, None) => {
|
||||
// Should be caught at the clap validation
|
||||
unreachable!();
|
||||
}
|
||||
(None, Some(config)) => {
|
||||
warn!(
|
||||
"Deprecated command line option. Please use: `neolink rtsp --config={:?}`",
|
||||
config
|
||||
);
|
||||
rtsp::main(rtsp::Opt { config })?;
|
||||
}
|
||||
(Some(_), Some(_)) => error!("--config should be given after the subcommand"),
|
||||
(Some(Command::Rtsp(opts)), None) => {
|
||||
rtsp::main(opts)?;
|
||||
}
|
||||
Command::StatusLight(opts) => {
|
||||
(Some(Command::StatusLight(opts)), None) => {
|
||||
statusled::main(opts)?;
|
||||
}
|
||||
Command::Reboot(opts) => {
|
||||
(Some(Command::Reboot(opts)), None) => {
|
||||
reboot::main(opts)?;
|
||||
}
|
||||
Command::Talk(opts) => {
|
||||
(Some(Command::Talk(opts)), None) => {
|
||||
talk::main(opts)?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user