Skip to content

🔖 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

ParameterTypeDescription
composerPathstringPath to the composer executable

Return Value

  • string: The full output of composer --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 GetInstalledVersion and IsComposerInstalled. 🔗
  • Also the way InstallWithProgress obtains the version during its post-install verification stage. ✅

Released under the MIT License