use super::completions;
use std::{env::args, ffi::OsString, process::exit};
use structopt::{clap, StructOpt};
pub trait StructOptUtils: StructOpt + Sized {
fn strict_from_iter(input: impl IntoIterator<Item = impl Into<OsString> + Clone>) -> Self {
match Self::from_iter_safe(input) as Result<Self, clap::Error> {
Ok(value) => value,
Err(clap::Error { kind, message, .. }) => match kind {
clap::ErrorKind::HelpDisplayed | clap::ErrorKind::VersionDisplayed => {
println!("{}", message);
exit(0);
}
_ => {
eprintln!("{}", message);
exit(1);
}
},
}
}
fn strict_from_args() -> Self {
Self::strict_from_iter(args())
}
fn run_completion_generator(name: &str, bin: &str) {
completions::App::new(name, bin).exec::<Self>()
}
}
impl<Args: StructOpt> StructOptUtils for Args {}