🔧 EnsureInstalled
Ensures that Composer is installed; if not installed and AutoInstall is enabled, it automatically installs and re-checks.
When to use
Call it at program startup to guarantee a usable Composer for subsequent commands. It is a "lazy" initialization, more flexible than auto-installing at construction time, and suited to deferred initialization scenarios.
Signature
go
func (c *Composer) EnsureInstalled() errorParameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| Single return value | error | Returns nil if already installed; returns an error if not installed and AutoInstall is off, or if installation fails |
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
options := composer.DefaultOptions()
options.AutoInstall = true
comp, err := composer.New(options)
if err != nil {
log.Fatalf("initialization failed: %v", err)
}
if err := comp.EnsureInstalled(); err != nil {
log.Fatalf("ensure installation failed: %v", err)
}
fmt.Println("Composer is ready ✅")
}Advanced
- For an installation progress callback, use
EnsureInstalledWithProgress. - To detect, install, and initialize in one step, use QuickSetup.
- To only check whether Composer is installed (without triggering installation), use IsInstalled.