Skip to content

🔖 GetInstalledVersion ​

Returns the version string of the installed Composer.

When to Use ​

Use this when you need to display the current Composer version or decide whether an upgrade is needed. It first locates the composer path, then runs composer --version. 📈

Signature ​

go
func (i *Installer) GetInstalledVersion() (string, error)

Parameters ​

ParameterTypeDescription
None—This method takes no parameters

Return Value ​

  • string: The full output of composer --version (with surrounding whitespace trimmed).
  • error: Returns ErrComposerNotFound when composer is not found; returns a wrapped error on execution failure. ⚠️

Example ​

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/installer"
)

func main() {
	i := installer.DefaultInstaller()
	version, err := i.GetInstalledVersion()
	if err != nil {
		log.Fatalf("failed to get version: %v", err)
	}
	fmt.Printf("current version: %s\n", version)
}

Advanced ​

  • Returns the entire line of output from composer --version (e.g. Composer version 2.7.1 ...); parse it yourself if you need the bare version number. 🛠️
  • Under the hood it calls the package-level function CheckComposerVersion. 🔗
  • You can use IsInstalled beforehand to avoid errors. ✅

Released under the MIT License