🎯 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
| Parameter | Type | Description |
|---|---|---|
options | *InstallOptions | Install options; pass nil to use DefaultInstallOptions() |
Return Value
*InstallResult: If already installed,Methodis"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
optionsenables features such as progress callbacks and context cancellation. 🛠️ - If you only want to query whether it is installed without triggering installation, use
IsComposerInstalled. ✅