From 6df59c5e154c2f587de743e675833f5157988b9b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 22 Feb 2026 23:28:29 +0900 Subject: 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 --- crates/mozart/src/main.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'crates/mozart/src/main.rs') diff --git a/crates/mozart/src/main.rs b/crates/mozart/src/main.rs index ed7c4ad..8201d87 100644 --- a/crates/mozart/src/main.rs +++ b/crates/mozart/src/main.rs @@ -40,6 +40,41 @@ fn init_tracing(profile: bool, verbose: u8, quiet: bool) { #[tokio::main] async fn main() { let cli = commands::Cli::parse(); + + if cli.version { + let build_date = option_env!("MOZART_BUILD_DATE").unwrap_or("source"); + // Line 1 (stdout): getLongVersion() equivalent + println!( + "{}", + mozart_core::console_format!( + "Mozart version {} {}", + env!("CARGO_PKG_VERSION"), + build_date + ) + ); + // Line 2 (stderr): PHP version + binary path (matches Composer's output) + let (php_version, php_binary) = mozart_core::platform::detect_php_version_and_binary() + .unwrap_or_else(|| ("not found".into(), "php".into())); + eprintln!( + "{}", + mozart_core::console_format!( + "PHP version {} ({})", + php_version, + php_binary + ) + ); + // Line 3 (stderr): diagnose hint + eprintln!("Run the \"diagnose\" command to get more detailed diagnostics output."); + return; + } + + let Some(ref _cmd) = cli.command else { + use clap::CommandFactory; + commands::Cli::command().print_help().ok(); + println!(); + return; + }; + init_tracing(cli.profile, cli.verbose, cli.quiet); match commands::execute(&cli).await { Ok(()) => {} -- cgit v1.3.1