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
39
40
use std::path::PathBuf;
use structopt::*;
pub use clap::Shell;
#[derive(StructOpt)]
#[structopt(name = "pretty-exec-completions", rename_all = "kebab")]
pub struct Args {
#[structopt(long, default_value = "pretty-exec")]
pub bin: String,
#[structopt(long, short = "o")]
pub output: Option<PathBuf>,
#[structopt(name = "shell", possible_values = &["bash", "fish", "zsh", "powershell", "elvish"])]
pub shell: Shell,
}
impl Args {
pub fn get(args: impl Iterator<Item = String>) -> Self {
use std::process::exit;
match Self::from_iter_safe(args) 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);
}
_ => {
println!("{}", message);
exit(1);
}
},
}
}
}