mai_cli/cli/completions_cmd.rs
1use crate::error::Result;
2use clap::{CommandFactory, Parser};
3use clap_complete::{Shell, generate};
4use std::io;
5
6#[derive(Parser, Debug)]
7pub struct CompletionsCommand {
8 /// The shell to generate completions for
9 #[arg(value_enum)]
10 pub shell: Shell,
11}
12
13impl CompletionsCommand {
14 pub fn run(&self) -> Result<()> {
15 let mut cmd = crate::cli::Cli::command();
16 let bin_name = cmd.get_name().to_string();
17 generate(self.shell, &mut cmd, bin_name, &mut io::stdout());
18 Ok(())
19 }
20}