Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pvm list available --search=<version>
pvm install <version> # pvm i <version>
# 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 <version> # pvm rm <version>
# Example: pvm uninstall 8.4 # pvm rm 8.4
Expand Down
2 changes: 1 addition & 1 deletion src/actions/use.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
23 changes: 19 additions & 4 deletions src/core/router.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Comment on lines +57 to +67
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please write a test covering the new added block on router.ps1
here is the file : router.tests.ps1


if (-not $version) {
Write-Host "`nPlease provide a PHP version to install"
return -1
Expand Down Expand Up @@ -250,15 +263,17 @@ function Get-Actions {
};
action = { return Invoke-PVMList -arguments $script:arguments }}
"install" = [PSCustomObject]@{
command = "pvm install <version>";
description = "The version must be a specific version.";
command = "pvm install <version>|[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 <version> (alias: pvm i <version>)"
USAGE = "pvm install <version> (alias: pvm i <version>) | 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 = @(
"<version> .... 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 }}
Expand Down