aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-21 23:50:43 +0900
committernsfisis <nsfisis@gmail.com>2026-02-21 23:50:43 +0900
commitb5af594fec7da72b15c9a202c641af0494db6355 (patch)
tree21f71831c8c638d14c538aebda93015e3bc484ae /crates
parent00dee137280be358ab9b40c6cff9af6efba1f17d (diff)
downloadphp-mozart-b5af594fec7da72b15c9a202c641af0494db6355.tar.gz
php-mozart-b5af594fec7da72b15c9a202c641af0494db6355.tar.zst
php-mozart-b5af594fec7da72b15c9a202c641af0494db6355.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/mozart/Cargo.toml1
-rw-r--r--crates/mozart/src/commands.rs5
-rw-r--r--crates/mozart/src/commands/completion.rs20
3 files changed, 26 insertions, 0 deletions
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(())
+}