use std::io;
use clap::CommandFactory;
use crate::cli::output::OutputConfig;
use crate::cli::Cli;
use crate::core::error::{SsError, ERR_STATE_WRITE_FAILED};
pub fn run_completion(shell: clap_complete::Shell, _output: &OutputConfig) -> Result<(), SsError> {
let mut cmd = Cli::command();
clap_complete::generate(shell, &mut cmd, "saferskills", &mut io::stdout());
Ok(())
}
pub fn run_man(_output: &OutputConfig) -> Result<(), SsError> {
let cmd = Cli::command();
let man = clap_mangen::Man::new(cmd);
man.render(&mut io::stdout()).map_err(|e| {
SsError::new(
ERR_STATE_WRITE_FAILED,
format!("Failed to render man page: {e}"),
)
})
}
#[cfg(test)]
mod tests {
use super::*;
use crate::cli::output::OutputFormat;
fn out() -> OutputConfig {
OutputConfig {
format: OutputFormat::Human,
verbose: false,
quiet: false,
color: false,
}
}
#[test]
fn completion_generates_for_each_shell() {
for shell in [
clap_complete::Shell::Bash,
clap_complete::Shell::Zsh,
clap_complete::Shell::Fish,
clap_complete::Shell::PowerShell,
] {
run_completion(shell, &out()).unwrap();
}
}
#[test]
fn man_renders() {
run_man(&out()).unwrap();
}
}