diff --git a/.gitignore b/.gitignore index 2f3f8f7..4a78939 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ flamegraph.svg perf.data perf.data.old **/target +_pacdef diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index e25048e..6202a0c 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -5,7 +5,6 @@ use std::path::Path; use anyhow::{anyhow, bail, ensure, Context, Result}; use clap::ArgMatches; -use clap_complete::{generate, shells::Zsh}; use const_format::formatcp; use crate::action::*; @@ -85,7 +84,7 @@ impl Pacdef { }, Some((VERSION, _)) => Ok(self.show_version()), - Some((COMPLETION, _)) => Ok(self.generate_shell_completion()), + Some((COMPLETION, _)) => generate_shell_completion(), Some((_, _)) => panic!("{ACTION_NOT_MATCHED}"), None => unreachable!("{UNREACHABLE_ARM}"), @@ -316,16 +315,6 @@ impl Pacdef { Ok(()) } - - #[allow(clippy::unused_self)] - fn generate_shell_completion(&self) { - generate( - Zsh, - &mut crate::args::build_cli(), - "pacdef", - &mut std::io::stdout(), - ); - } } /// For the provided CLI arguments, get the path to each corresponding group file. @@ -393,3 +382,15 @@ pub const fn get_version_string() -> &'static str { formatcp!("{VERSION} ({HASH})") } } + +fn generate_shell_completion() -> Result<()> { + let mut output = File::create("_pacdef")?; + clap_complete::generate( + clap_complete::Shell::Zsh, + &mut crate::args::build_cli(), + "pacdef", + &mut output, + ); + println!("completion written to _pacdef"); + Ok(()) +}