structopt_utilities/
traits.rs1use super::completions;
2use std::{env::args, ffi::OsString, process::exit};
3use structopt::{clap, StructOpt};
4
5pub trait StructOptUtils: StructOpt + Sized {
7 fn strict_from_iter(input: impl IntoIterator<Item = impl Into<OsString> + Clone>) -> Self {
12 match Self::from_iter_safe(input) as Result<Self, clap::Error> {
13 Ok(value) => value,
14 Err(clap::Error { kind, message, .. }) => match kind {
15 clap::ErrorKind::HelpDisplayed | clap::ErrorKind::VersionDisplayed => {
16 println!("{}", message);
17 exit(0);
18 }
19 _ => {
20 eprintln!("{}", message);
21 exit(1);
22 }
23 },
24 }
25 }
26
27 fn strict_from_args() -> Self {
29 Self::strict_from_iter(args())
30 }
31
32 fn run_completion_generator(name: &str, bin: &str) {
34 completions::App::new(name, bin).exec::<Self>()
35 }
36}
37
38impl<Args: StructOpt> StructOptUtils for Args {}