⚡ InstallWithProgress
Performs a smart install with progress callbacks, automatic retries, and context cancellation.
When to Use
Use this when you need to display installation progress in a CLI/UI, automatically retry on failure, or allow the user to cancel mid-install. This is the most full-featured install entry point. 🚀
Signature
go
func (si *SmartInstaller) InstallWithProgress() (*InstallResult, error)Parameters
| Parameter | Type | Description |
|---|---|---|
| None (explicit) | — | Behavior is determined by the InstallOptions passed to NewSmartInstaller(options) |
Return Value
*InstallResult: Contains fields such asSuccess,ComposerPath,Version,PHPVersion,Method,Duration, andStages. ✅error: Errors during installation (returned after retryingMaxRetriestimes without success). ⚠️
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/installer"
)
func main() {
opts := installer.DefaultInstallOptions()
opts.ProgressCallback = func(p installer.InstallProgress) {
fmt.Printf("[%s] %s (%d%%)\n", p.Stage, p.Message, p.Percent)
}
si := installer.NewSmartInstaller(opts)
result, err := si.InstallWithProgress()
if err != nil {
log.Fatalf("installation failed: %v", err)
}
fmt.Printf("Composer %s installed successfully, path: %s\n", result.Version, result.ComposerPath)
}Advanced
- Install stages are represented by
InstallStageconstants, e.g.StageCheckingPHP,StageDownloading,StageVerifying,StageCompleted. 📊 - Installation can be cancelled at any time via
InstallOptions.Context;MaxRetries/RetryDelaycontrol the retry strategy. 🔄 - If you only need to "ensure installed", a more convenient entry point is
EnsureComposerInstalled. 🎯 - Set
SkipVerificationto skip post-install verification and speed up the flow. ⚡