use std::io::{self, Write};
use clap::CommandFactory;
use clap_complete::Shell;
use super::*;
#[derive(clap::Args, Debug)]
#[command(after_long_help = "\
Examples:
mnem completions bash > ~/.local/share/bash-completion/completions/mnem
mnem completions zsh > ~/.zsh/completions/_mnem
mnem completions fish > ~/.config/fish/completions/mnem.fish
mnem completions powershell >> $PROFILE
mnem completions elvish > ~/.config/elvish/lib/mnem.elv
")]
pub(crate) struct Args {
#[arg(value_enum)]
pub shell: Shell,
}
pub(crate) fn run(args: Args) -> Result<()> {
let mut cmd = crate::Cli::command();
let mut buf: Vec<u8> = Vec::with_capacity(64 * 1024);
clap_complete::generate(args.shell, &mut cmd, "mnem", &mut buf);
match io::stdout().write_all(&buf) {
Ok(()) => Ok(()),
Err(e) if e.kind() == io::ErrorKind::BrokenPipe => Ok(()),
Err(e) => Err(e.into()),
}
}