Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ pvm extensions disable xdebug
```
Will disable an extension or Zend extension in the active version's `php.ini`.

```
pvm update [--yes-update|-y]
```
Check for a newer `pvm` release. When a newer release is found, `pvm update` will run the installer automatically (no interactive prompt).

- `--yes-update`, `-y`: when provided, `pvm update` prefers the safe download-and-replace installer path (the default non-interactive flow used in CI/testing).

The installer executed by the quick-install command is:

```powershell
irm https://pvm.hjb.dev/install.ps1 | iex
```

Notes:

- `PVM_INSTALL_SCRIPT`: optional environment variable pointing to a custom installer. Can be a URL (http/https) or a local PowerShell script path. When set, `pvm update` will run this installer instead of the default download flow.
- `PVM_INSTALL_CHECKSUM`: optional SHA256 hex string used to verify the downloaded `pvm.exe` when using the automatic download path.
- Safe update behavior: by default `pvm update` will download the `pvm.exe` release asset, optionally verify its checksum, back up the existing `pvm.exe` to `pvm.exe.bak`, atomically replace the binary and verify the installed version. On verification failure it will attempt to roll back to the backup.

## Composer support
`pvm` now installs also composer with each php version installed.
It will install Composer latest stable release for PHP >= 7.2 and Composer latest 2.2.x LTS for PHP < 7.2.
Expand Down
21 changes: 21 additions & 0 deletions commands/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"
"hjbdev/pvm/theme"
"os"

"github.com/fatih/color"
)
Expand All @@ -13,6 +14,25 @@ func Help(notFoundError bool) {
theme.Title("pvm: PHP Version Manager")
theme.Info(fmt.Sprintf("Version %s", version))

// Check for updates in background (best-effort). If env PVM_AUTO_UPDATE=1, run installer.
if latest, newer, err := CheckForUpdate(version); err == nil {
// show latest always
theme.Info(fmt.Sprintf("Latest %s", latest))
if newer {
theme.Info("A newer version is available.")
if os.Getenv("PVM_AUTO_UPDATE") == "1" {
theme.Info("Auto-update enabled. Running installer...")
if err := InstallLatest(true); err != nil {
theme.Error(fmt.Sprintf("Auto-install failed: %v", err))
}
} else {
theme.Info(fmt.Sprintf("Run the installer: irm https://pvm.hjb.dev/install.ps1 | iex"))
}
}
} else {
// non-fatal: hide network error
}

if notFoundError {
theme.Error("Command not found")
}
Expand All @@ -21,6 +41,7 @@ func Help(notFoundError bool) {
printHelpCommand("extensions <list|ls|enable|disable> [extension[,extension...]]", "e")
printHelpCommand("help")
printHelpCommand("install", "i")
printHelpCommand("update", "")
printHelpCommand("list [remote]", "ls")
printHelpCommand("bin")
printHelpCommand("use <version>", "u")
Expand Down
16 changes: 14 additions & 2 deletions commands/list-remote.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package commands

import (
"fmt"
"os"

"hjbdev/pvm/common"
"hjbdev/pvm/theme"
"slices"
Expand All @@ -21,8 +24,17 @@ func ListRemote() error {

installedVersions, _ := retrieveInstalledPHPVersions()

currentVersion := common.GetCurrentVersionFolder()
currentVersionNumber, currentVersionErr := common.ParseVersion(currentVersion, common.IsThreadSafeName(currentVersion), "")
// Only attempt to read the current-version metadata when HOME is set
// (tests set HOME when they want to provide a controlled environment).
var currentVersion string
var currentVersionNumber common.Version
var currentVersionErr error
if os.Getenv("HOME") != "" {
currentVersion = common.GetCurrentVersionFolder()
currentVersionNumber, currentVersionErr = common.ParseVersion(currentVersion, common.IsThreadSafeName(currentVersion), "")
} else {
currentVersionErr = fmt.Errorf("HOME not set")
}

theme.Title("PHP versions available")
for _, version := range versions {
Expand Down
Loading