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-core/src | |
| 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-core/src')
| -rw-r--r-- | crates/mozart-core/src/platform.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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<PlatformPackage> { } } +/// 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<String> { let output = std::process::Command::new("php") |
