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-core/src/platform.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crates/mozart-core/src') diff --git a/crates/mozart-core/src/platform.rs b/crates/mozart-core/src/platform.rs index 317a75f..819d8c9 100644 --- a/crates/mozart-core/src/platform.rs +++ b/crates/mozart-core/src/platform.rs @@ -265,6 +265,23 @@ pub fn parse_platform_info(output: &str) -> Vec { } } +/// Detect PHP version and binary path for `--version` display. +/// +/// Returns `(PHP_VERSION, PHP_BINARY)` by running a single PHP invocation. +/// Returns `None` if PHP is not available. +pub fn detect_php_version_and_binary() -> Option<(String, String)> { + let output = std::process::Command::new("php") + .args(["-r", r#"echo PHP_VERSION, "\n", PHP_BINARY;"#]) + .output() + .ok()?; + if !output.status.success() { + return None; + } + let stdout = String::from_utf8(output.stdout).ok()?; + let mut lines = stdout.lines(); + Some((lines.next()?.to_owned(), lines.next()?.to_owned())) +} + /// Try to detect the installed PHP version by running `php --version`. pub fn detect_php_version() -> Option { let output = std::process::Command::new("php") -- cgit v1.3.1