use crate::Runtasktic;
use anyhow::Result;
use clap::{CommandFactory, Parser};
use clap_complete::{Shell, generate};
#[derive(Parser, Debug)]
pub enum Completion {
#[command(name = "bash")]
Bash,
#[command(name = "fish")]
Fish,
#[command(name = "zsh")]
Zsh,
#[command(name = "elvish")]
Elvish,
}
impl Completion {
pub fn exec(&self) -> Result<()> {
let shell = match self {
Completion::Bash => Shell::Bash,
Completion::Fish => Shell::Fish,
Completion::Zsh => Shell::Zsh,
Completion::Elvish => Shell::Elvish,
};
let mut cli = Runtasktic::command();
let bin_name = cli.get_name().to_string();
generate(shell, &mut cli, &bin_name, &mut std::io::stdout());
Ok(())
}
}