🚀 Auto-Install Example
This example demonstrates how to use the installer package to install Composer and PHP in one shot, suitable for CI/CD pipelines or AI automation scenarios.
📦 Core Capabilities
🔧 Code Example
go
package main
import (
"fmt"
"log"
"time"
"github.com/scagogogo/composer-skills/pkg/installer"
)
func main() {
// Configuration: SmartConfig automatically picks the best strategy per platform
cfg := installer.SmartConfig()
cfg.AutoInstallPHP = true // Auto-install PHP when missing
opts := &installer.InstallOptions{
Config: cfg,
MaxRetries: 3,
RetryDelay: 5 * time.Second,
ProgressCallback: func(p installer.InstallProgress) {
fmt.Printf("[%s] %d%% %s\n", p.Stage, p.Percent, p.Message)
},
}
// One-shot install
result, err := installer.EnsureComposerInstalled(opts)
if err != nil || !result.Success {
log.Fatalf("Install failed: %v", err)
}
fmt.Printf("Composer: %s @ %s\n", result.Version, result.ComposerPath)
fmt.Printf("PHP: %s\n", result.PHPVersion)
}🖥️ Platform Strategies
| Platform | PHP Install Method | Composer Install Method |
|---|---|---|
| 🐧 Linux | apt / dnf / pacman / apk (by distro) | Package manager first; otherwise download phar |
| 🍎 macOS | brew install php | brew install composer or download phar |
| 🪟 Windows | Download zip from php.net, extract to user dir | Download composer.phar + .cmd wrapper |
🎯 When to Use
- CI container startup — no PHP/Composer on the runner; one command does it all
- AI automation — AI scripts don't need to worry about the environment; just call
EnsureComposerInstalled - Dev machine bootstrap — new teammates set up their environment by running a single script
CLI one-shot command
The composer-skills install command wraps all of the above logic. Run it directly in your terminal:
bash
composer-skills install # Install Composer + PHP
composer-skills install --php-only # Install PHP only🧭 Related Docs
- 📦 Installer overview — Config / SmartInstaller API
- 🔧 Auto-install mechanism — Process walkthrough
- 🖥️ Cross-platform support — Three-platform strategy matrix