pub fn generate<G, S>(app: &mut clap::App, bin_name: S, buf: &mut dyn Write)
where
    G: Generator,
    S: Into<String>,
{
    app.set_bin_name(bin_name);

    if !app.is_set(clap::AppSettings::Built) {
        app._build();
        app._build_bin_names();
    }

    G::generate(app, buf)
}
/// Generate a completions file for a specified shell at runtime.
///
/// Until `cargo install` can install extra files like a completion script, this may be
/// used e.g. in a command that outputs the contents of the completion script, to be
/// redirected into a file by the user.
///
/// # Examples
///
/// Assuming a separate `cli.rs` like the [example above](./fn.generate_to.html),
/// we can let users generate a completion script using a command:
///
/// ```ignore
/// // src/main.rs
///
/// mod cli;
/// use std::io;
/// use clap_generate::{generate, generators::Bash};
///
/// fn main() {
///     let matches = cli::build_cli().get_matches();
///
///     if matches.is_present("generate-bash-completions") {
///         generate::<Bash, _>(&mut cli::build_cli(), "myapp", &mut io::stdout());
///     }
///
///     // normal logic continues...
/// }
///
/// ```
///
/// Usage:
///
/// ```shell
/// $ myapp generate-bash-completions > /usr/share/bash-completion/completions/myapp.bash
/// ```
Generate a completions file for a specified shell at runtime.
Until `cargo install` can install extra files like a completion script, this may be
used e.g. in a command that outputs the contents of the completion script, to be
redirected into a file by the user.
Generate a completions file for a specified shell at runtime . Until ` cargo install ` can install extra files like a completion script this may be used e . g . in a command that outputs the contents of the completion script to be redirected into a file by the user .
pub fn generate<G, S>(app: &mut clap::App, bin_name: S, buf: &mut dyn Write)
where
    G: Generator,
    S: Into<String>,
{
    app.set_bin_name(bin_name);
    if !app.is_set(clap::AppSettings::Built) {
        app._build();
        app._build_bin_names();
    }
    G::generate(app, buf)
}
pub fn generate < G , S > ( app : & mut clap :: App , bin_name : S , buf : & mut dyn Write ) where G : Generator , S : Into < String > , { app . set_bin_name ( bin_name ) ; if ! app . is_set ( clap :: AppSettings :: Built ) { app . _build ( ) ; app . _build_bin_names ( ) ; } G :: generate ( app , buf ) }
Generate a completions file for a specified shell at runtime.
Generate a completions file for a specified shell at runtime .
app
&mut clap::App
bin_name
S
buf
&mut dyn Write
app
&mut clap::App
bin_name
S
buf
&mut dyn Write
examples
Assuming a separate `cli.rs` like the [example above](./fn.generate_to.html),
we can let users generate a completion script using a command.

```ignore
src/main.rs

mod cli;
use std::io;
use clap_generate::{generate, generators::Bash}.

fn main() {
let matches = cli::build_cli().get_matches().

if matches.is_present("generate-bash-completions") {
generate::(&mut cli::build_cli(), "myapp", &mut io::stdout());
}

normal logic continues
}





```shell
$ myapp generate-bash-completions > /usr/share/bash-completion/completions/myapp.bash
```
Assuming a separate ` cli . rs ` like the [ example above ] ( . / fn . generate_to . html ) we can let users generate a completion script using a command . ` ` ` ignore src / main . rs mod cli ; use std :: io ; use clap_generate :: { generate generators :: Bash } . fn main () { let matches = cli :: build_cli () . get_matches () . if matches . is_present ( " generate - bash - completions " ) { generate :: ( &mut cli :: build_cli () " myapp " &mut io :: stdout () ) ; } normal logic continues } ` ` ` shell $ myapp generate - bash - completions > / usr / share / bash - completion / completions / myapp . bash ` ` `