structopt_utilities/completions/
exec.rs

1use super::App;
2use pipe_trait::*;
3use std::{
4    fs::File,
5    io::{stdout, Write},
6};
7use structopt::StructOpt;
8
9impl App {
10    /// Run the completion generator
11    pub fn exec<Target: StructOpt>(self) {
12        let App { bin, output, shell } = self;
13
14        let mut buf: Box<dyn Write> = if let Some(file_name) = output {
15            file_name.pipe(File::create).unwrap().pipe(Box::new)
16        } else {
17            Box::new(stdout())
18        };
19
20        Target::clap().gen_completions_to(bin, shell.to_clap(), &mut buf);
21    }
22}