diff options
| -rw-r--r-- | examples/example-completion/src/main.rs | 8 | ||||
| -rw-r--r-- | mingling/src/example_docs.rs | 8 | ||||
| -rw-r--r-- | mingling_core/src/builds/comp.rs | 36 |
3 files changed, 24 insertions, 28 deletions
diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs index 86a00ca..141f84e 100644 --- a/examples/example-completion/src/main.rs +++ b/examples/example-completion/src/main.rs @@ -13,11 +13,11 @@ //! ```ignore //! use mingling::build::{build_comp_scripts, build_comp_scripts_with_bin_name}; //! fn main() { -//! // Generate completion scripts for the current program -//! build_comp_scripts().unwrap(); +//! // Generate completion scripts for the current program, using the Cargo package name as the binary filename +//! build_comp_scripts(env!("CARGO_PKG_NAME")).unwrap(); //! -//! // Or specify a specific name -//! // build_comp_scripts_with_bin_name("your_bin").unwrap(); +//! // Or, explicitly specify the binary filename +//! // build_comp_scripts("your_bin").unwrap(); //! } //! ``` //! diff --git a/mingling/src/example_docs.rs b/mingling/src/example_docs.rs index 1260509..1ee5118 100644 --- a/mingling/src/example_docs.rs +++ b/mingling/src/example_docs.rs @@ -82,11 +82,11 @@ pub mod example_basic {} /// ```ignore /// use mingling::build::{build_comp_scripts, build_comp_scripts_with_bin_name}; /// fn main() { -/// // Generate completion scripts for the current program -/// build_comp_scripts().unwrap(); +/// // Generate completion scripts for the current program, using the Cargo package name as the binary filename +/// build_comp_scripts(env!("CARGO_PKG_NAME")).unwrap(); /// -/// // Or specify a specific name -/// // build_comp_scripts_with_bin_name("your_bin").unwrap(); +/// // Or, explicitly specify the binary filename +/// // build_comp_scripts("your_bin").unwrap(); /// } /// ``` /// diff --git a/mingling_core/src/builds/comp.rs b/mingling_core/src/builds/comp.rs index 57faa2e..754aff4 100644 --- a/mingling_core/src/builds/comp.rs +++ b/mingling_core/src/builds/comp.rs @@ -7,23 +7,6 @@ const TMPL_COMP_ZSH: &str = include_str!("../../tmpls/comps/zsh.zsh"); const TMPL_COMP_FISH: &str = include_str!("../../tmpls/comps/fish.fish"); const TMPL_COMP_PWSH: &str = include_str!("../../tmpls/comps/pwsh.ps1"); -/// Generate shell completion scripts for the current binary. -/// On Windows, generates PowerShell completion. -/// On Linux, generates Zsh, Bash, and Fish completions. -/// Scripts are written to the `OUT_DIR` (or `target/` if `OUT_DIR` is not set). -/// -/// # Example -/// ``` -/// // Typically called from a build script (`build.rs`): -/// build_comp_scripts().unwrap(); -/// // Or, to specify a custom binary name: -/// build_comp_scripts_with_bin_name("myapp").unwrap(); -/// ``` -pub fn build_comp_scripts() -> Result<(), std::io::Error> { - let bin_name = env!("CARGO_PKG_NAME"); - build_comp_scripts_with_bin_name(bin_name) -} - /// Generate shell completion scripts for a given binary name. /// On Windows, generates PowerShell completion. /// On Linux, generates Zsh, Bash, and Fish completions. @@ -32,9 +15,12 @@ pub fn build_comp_scripts() -> Result<(), std::io::Error> { /// # Example /// ``` /// // Generate completion scripts for "myapp" -/// build_comp_scripts_with_bin_name("myapp").unwrap(); +/// build_comp_scripts("myapp").unwrap(); +/// +/// // Generate completion scripts for current package +/// build_comp_scripts(env!("CARGO_PKG_NAME")).unwrap(); /// ``` -pub fn build_comp_scripts_with_bin_name(name: &str) -> Result<(), std::io::Error> { +pub fn build_comp_scripts(name: &str) -> Result<(), std::io::Error> { #[cfg(target_os = "windows")] { build_comp_script(&ShellFlag::Powershell, name)?; @@ -58,7 +44,17 @@ pub fn build_comp_scripts_with_bin_name(name: &str) -> Result<(), std::io::Error } } -fn build_comp_script(shell_flag: &ShellFlag, bin_name: &str) -> Result<(), std::io::Error> { +/// Generate a shell completion script for a specific shell. +/// +/// This function takes a shell flag and a binary name, selects the appropriate +/// template, substitutes the binary name into the template, and writes the +/// resulting completion script to the target directory (typically `target/`). +/// +/// # Example +/// ``` +/// build_comp_script(&ShellFlag::Bash, "myapp").unwrap(); +/// ``` +pub fn build_comp_script(shell_flag: &ShellFlag, bin_name: &str) -> Result<(), std::io::Error> { let (tmpl_str, ext) = get_tmpl(shell_flag); let mut tmpl = just_template::Template::from(tmpl_str); tmpl_param!(tmpl, bin_name = bin_name); |
