1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 {}