use anyhow::Result;
use clap::CommandFactory;
pub(crate) fn run(shell: clap_complete::Shell) -> Result<()> {
let mut cmd = crate::Cli::command();
let mut buf: Vec<u8> = Vec::new();
clap_complete::generate(shell, &mut cmd, "aviso", &mut buf);
crate::output::write_stdout_bytes(&buf)
}
#[cfg(test)]
#[allow(
clippy::unwrap_used,
clippy::expect_used,
reason = "test code: unwrap/expect on completions generation is the expected diagnostic"
)]
mod tests {
use clap::CommandFactory;
use clap_complete::Shell;
#[test]
fn generates_non_empty_bash_completions() {
let mut cmd = crate::Cli::command();
let mut buf: Vec<u8> = Vec::new();
clap_complete::generate(Shell::Bash, &mut cmd, "aviso", &mut buf);
assert!(!buf.is_empty());
let s = String::from_utf8_lossy(&buf);
assert!(
s.contains("aviso") || s.contains("_aviso"),
"completion script should name the binary"
);
}
#[test]
fn generates_non_empty_zsh_completions() {
let mut cmd = crate::Cli::command();
let mut buf: Vec<u8> = Vec::new();
clap_complete::generate(Shell::Zsh, &mut cmd, "aviso", &mut buf);
assert!(!buf.is_empty());
}
#[test]
fn generates_non_empty_fish_completions() {
let mut cmd = crate::Cli::command();
let mut buf: Vec<u8> = Vec::new();
clap_complete::generate(Shell::Fish, &mut cmd, "aviso", &mut buf);
assert!(!buf.is_empty());
}
}