use super::*;
use crate::{cli, Result};
use clap::CommandFactory;
use clap_complete::{generate, Shell};
use std::sync::atomic::AtomicBool;
#[derive(Clone, Debug, Parser)]
pub(crate) struct ShellCompletions {
#[clap(value_enum)]
pub shell: Shell,
}
pub static GENERATING_COMPLETIONS: AtomicBool = AtomicBool::new(false);
impl ShellCompletions {
pub fn generate_and_print(self) -> Result<StructuredOutput> {
let mut cmd = cli::Cli::command();
GENERATING_COMPLETIONS.swap(true, std::sync::atomic::Ordering::Relaxed);
generate(
self.shell,
&mut cmd,
env!("CARGO_BIN_NAME"),
&mut std::io::stdout(),
);
Ok(StructuredOutput::Success)
}
}