diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-22 23:28:29 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-22 23:28:29 +0900 |
| commit | 6df59c5e154c2f587de743e675833f5157988b9b (patch) | |
| tree | bfdd36b8f5ffd29e27b8f8464033d76dedbb7214 /crates/mozart/src/commands.rs | |
| parent | 9acffe293fdf05fcaf72fb941a13912f31ddfbf8 (diff) | |
| download | php-mozart-6df59c5e154c2f587de743e675833f5157988b9b.tar.gz php-mozart-6df59c5e154c2f587de743e675833f5157988b9b.tar.zst php-mozart-6df59c5e154c2f587de743e675833f5157988b9b.zip | |
feat(cli): match Composer's --version output format
Replace clap's built-in --version with custom handler that outputs
Composer-compatible version info: Mozart version line, PHP version
with binary path, and diagnose hint. Add detect_php_version_and_binary()
to mozart-core platform module.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands.rs')
| -rw-r--r-- | crates/mozart/src/commands.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/crates/mozart/src/commands.rs b/crates/mozart/src/commands.rs index 968763f..e633526 100644 --- a/crates/mozart/src/commands.rs +++ b/crates/mozart/src/commands.rs @@ -35,10 +35,14 @@ pub mod update; pub mod validate; #[derive(clap::Parser)] -#[command(name = "mozart", version, about = "A PHP dependency manager")] +#[command(name = "mozart", about = "A PHP dependency manager")] pub struct Cli { #[command(subcommand)] - pub command: Commands, + pub command: Option<Commands>, + + /// Display version information + #[arg(short = 'V', long = "version")] + pub version: bool, /// Increase the verbosity of messages: 1 for normal, 2 for more verbose, 3 for debug #[arg(short, long, action = clap::ArgAction::Count, global = true)] @@ -238,7 +242,7 @@ impl Commands { } } -#[tracing::instrument(skip(cli), fields(command = cli.command.name()))] +#[tracing::instrument(skip(cli), fields(command = cli.command.as_ref().map(|c| c.name()).unwrap_or("none")))] pub async fn execute(cli: &Cli) -> anyhow::Result<()> { let console = mozart_core::console::Console::new( cli.verbose, @@ -247,7 +251,8 @@ pub async fn execute(cli: &Cli) -> anyhow::Result<()> { cli.no_ansi, cli.no_interaction, ); - match &cli.command { + let command = cli.command.as_ref().expect("command must be set"); + match command { Commands::About(args) => about::execute(args, cli, &console).await, Commands::Archive(args) => archive::execute(args, cli, &console).await, Commands::Audit(args) => audit::execute(args, cli, &console).await, |
