From b5af594fec7da72b15c9a202c641af0494db6355 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 21 Feb 2026 23:50:43 +0900 Subject: feat(completion): add shell completion generation via clap_complete Add a `completion` subcommand that generates shell completion scripts for Bash, Zsh, Fish, Elvish, and PowerShell using the clap_complete crate. Co-Authored-By: Claude Opus 4.6 --- crates/mozart/Cargo.toml | 1 + crates/mozart/src/commands.rs | 5 +++++ crates/mozart/src/commands/completion.rs | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 crates/mozart/src/commands/completion.rs (limited to 'crates') diff --git a/crates/mozart/Cargo.toml b/crates/mozart/Cargo.toml index e219fff..ccf7f94 100644 --- a/crates/mozart/Cargo.toml +++ b/crates/mozart/Cargo.toml @@ -8,6 +8,7 @@ anyhow = "1.0.101" bzip2 = "0.5" filetime = "0.2" clap = { version = "4.5.57", features = ["derive"] } +clap_complete = "4" colored = "3.1.1" dialoguer = "0.12.0" flate2 = "1" diff --git a/crates/mozart/src/commands.rs b/crates/mozart/src/commands.rs index 694b4e1..285f65d 100644 --- a/crates/mozart/src/commands.rs +++ b/crates/mozart/src/commands.rs @@ -5,6 +5,7 @@ pub mod browse; pub mod bump; pub mod check_platform_reqs; pub mod clear_cache; +pub mod completion; pub mod config; pub mod create_project; pub mod dependency; @@ -105,6 +106,9 @@ pub enum Commands { #[command(name = "clear-cache", alias = "clearcache", alias = "cc")] ClearCache(clear_cache::ClearCacheArgs), + /// Generate shell completion scripts + Completion(completion::CompletionArgs), + /// Sets config options Config(config::ConfigArgs), @@ -203,6 +207,7 @@ pub fn execute(cli: &Cli) -> anyhow::Result<()> { Commands::Bump(args) => bump::execute(args, cli, &console), Commands::CheckPlatformReqs(args) => check_platform_reqs::execute(args, cli, &console), Commands::ClearCache(args) => clear_cache::execute(args, cli, &console), + Commands::Completion(args) => completion::execute(args, cli, &console), Commands::Config(args) => config::execute(args, cli, &console), Commands::CreateProject(args) => create_project::execute(args, cli, &console), Commands::Depends(args) => depends::execute(args, cli, &console), diff --git a/crates/mozart/src/commands/completion.rs b/crates/mozart/src/commands/completion.rs new file mode 100644 index 0000000..406749c --- /dev/null +++ b/crates/mozart/src/commands/completion.rs @@ -0,0 +1,20 @@ +use clap::Args; +use clap::CommandFactory; +use clap_complete::aot::Shell; + +#[derive(Args)] +pub struct CompletionArgs { + /// The shell to generate completions for + #[arg(value_enum)] + pub shell: Shell, +} + +pub fn execute( + args: &CompletionArgs, + _cli: &super::Cli, + _console: &crate::console::Console, +) -> anyhow::Result<()> { + let mut cmd = super::Cli::command(); + clap_complete::aot::generate(args.shell, &mut cmd, "mozart", &mut std::io::stdout()); + Ok(()) +} -- cgit v1.3.1