🔖 CheckComposerVersion
Runs composer --version and returns the version string.
When to Use
Use this when you need to obtain the version output of a specific composer executable. Commonly used for post-install verification or version display. ✅
Signature
go
func CheckComposerVersion(composerPath string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
composerPath | string | Path to the composer executable |
Return Value
string: The full output ofcomposer --version(with surrounding whitespace trimmed).error: Returns a wrapped error on execution failure (e.g. invalid path). ⚠️
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/installer"
)
func main() {
version, err := installer.CheckComposerVersion("/usr/local/bin/composer")
if err != nil {
log.Fatalf("failed to get version: %v", err)
}
fmt.Printf("version: %s\n", version)
}Advanced
- Returns the entire line of output (e.g.
Composer version 2.7.1 ...); you need to parse out the bare version number yourself. 🛠️ - Internally called by
GetInstalledVersionandIsComposerInstalled. 🔗 - Also the way
InstallWithProgressobtains the version during its post-install verification stage. ✅