From e4abcb9733c4e06318666ccfaf0327f84bfac28d Mon Sep 17 00:00:00 2001 From: faissaloux Date: Mon, 15 Sep 2025 22:38:19 +0100 Subject: [PATCH 1/2] install auto --- src/actions/use.ps1 | 2 +- src/core/router.ps1 | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/actions/use.ps1 b/src/actions/use.ps1 index 94198f1..2c3a936 100644 --- a/src/actions/use.ps1 +++ b/src/actions/use.ps1 @@ -91,7 +91,7 @@ function Auto-Select-PHP-Version { if (-not $installedVersions) { $message = "PHP '$version' is not installed." $message += "`nRun: pvm install $version" - return @{ code = -1; message = $message; } + return @{ code = -1; version = $version; message = $message; } } return @{ code = 0; version = $version; } diff --git a/src/core/router.ps1 b/src/core/router.ps1 index 5a4788c..46b1549 100644 --- a/src/core/router.ps1 +++ b/src/core/router.ps1 @@ -52,7 +52,20 @@ function Invoke-PVMList{ function Invoke-PVMInstall { param($arguments) - $version = $arguments[0] + $version = $arguments[0] + + if ($version -eq 'auto') { + $result = Auto-Select-PHP-Version + + if ($result.code -eq 0) { + $version = $result.version + Display-Msg-By-ExitCode -result $result -message "php $version is already installed!" + return -1 + } + + $version = $result.version + } + if (-not $version) { Write-Host "`nPlease provide a PHP version to install" return -1 From 77c037d6a1e26834717cc84a406f6edf91b6ec09 Mon Sep 17 00:00:00 2001 From: faissaloux Date: Mon, 15 Sep 2025 22:38:40 +0100 Subject: [PATCH 2/2] install auto documentation --- readme.md | 3 +++ src/core/router.ps1 | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 1b52bb4..992213e 100644 --- a/readme.md +++ b/readme.md @@ -59,6 +59,9 @@ pvm list available --search= pvm install # pvm i # Example: pvm install 8.4 # pvm i 8.4 +# Install the php version specified on your project. +pvm install auto # pvm i auto + # Uninstall a specific version pvm uninstall # pvm rm # Example: pvm uninstall 8.4 # pvm rm 8.4 diff --git a/src/core/router.ps1 b/src/core/router.ps1 index 46b1549..f310269 100644 --- a/src/core/router.ps1 +++ b/src/core/router.ps1 @@ -263,15 +263,17 @@ function Get-Actions { }; action = { return Invoke-PVMList -arguments $script:arguments }} "install" = [PSCustomObject]@{ - command = "pvm install "; - description = "The version must be a specific version."; + command = "pvm install |[auto]"; + description = "The version must be a specific version. use 'auto' to install the version specified in the current directory's composer.json or .php-version file."; usage = [ordered]@{ - USAGE = "pvm install (alias: pvm i )" + USAGE = "pvm install (alias: pvm i ) | pvm install auto" DESCRIPTION = @( "Downloads and installs the PHP version, including opcache and xdebug." + "or use 'auto' to automatically select the version based on project configuration files." ) ARGUMENTS = @( " .... The version must be a number e.g. 8, 8.2 or 8.2.0 (required)" + "auto ......... Auto-detect version from project files" ) } action = { return Invoke-PVMInstall -arguments $script:arguments }}