Skip to content

🎯 EnsureComposerInstalled ​

Ensures that Composer is installed; if not, automatically performs a smart install.

When to Use ​

Use this when your program depends on Composer being present but you don't want to split it into "check" and "install" steps. This is the most common bootstrap entry point. 🚀

Signature ​

go
func EnsureComposerInstalled(options *InstallOptions) (*InstallResult, error)

Parameters ​

ParameterTypeDescription
options*InstallOptionsInstall options; pass nil to use DefaultInstallOptions()

Return Value ​

  • *InstallResult: If already installed, Method is "already_installed"; otherwise the install result. ✅
  • error: Returns an error if installation fails. ⚠️

Example ​

go
package main

import (
	"fmt"
	"log"

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

func main() {
	result, err := installer.EnsureComposerInstalled(nil)
	if err != nil {
		log.Fatalf("failed to ensure Composer installed: %v", err)
	}
	fmt.Printf("Composer ready: %s (version %s)\n", result.ComposerPath, result.Version)
}

Advanced ​

  • Returns immediately if already installed; otherwise delegates to InstallWithProgress. 🔄
  • Passing custom options enables features such as progress callbacks and context cancellation. 🛠️
  • If you only want to query whether it is installed without triggering installation, use IsComposerInstalled. ✅

Released under the MIT License