Skip to content

⚡ 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

ParameterTypeDescription
None (explicit)Behavior is determined by the InstallOptions passed to NewSmartInstaller(options)

Return Value

  • *InstallResult: Contains fields such as Success, ComposerPath, Version, PHPVersion, Method, Duration, and Stages. ✅
  • error: Errors during installation (returned after retrying MaxRetries times 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 InstallStage constants, e.g. StageCheckingPHP, StageDownloading, StageVerifying, StageCompleted. 📊
  • Installation can be cancelled at any time via InstallOptions.Context; MaxRetries/RetryDelay control the retry strategy. 🔄
  • If you only need to "ensure installed", a more convenient entry point is EnsureComposerInstalled. 🎯
  • Set SkipVerification to skip post-install verification and speed up the flow. ⚡

Released under the MIT License