🔧 Auto-install mechanism
One of the most convenient features of Composer Skills: Target machine doesn't have Composer? The SDK installs it itself. This page explains how the "detect → check PHP → install → verify → ready" chain works and how to trigger it in your code.
🔄 Process overview
When Options.AutoInstall = true (the default), creating a *Composer instance triggers this flow:
Enabled by default
composer.DefaultOptions() returns Options with AutoInstall: true, so this single line includes the full detection-and-install logic:
comp, err := composer.New(composer.DefaultOptions())🚀 QuickSetup: all in one step
If you find New + SetWorkingDir too verbose, use QuickSetup to complete detection, installation, and instance creation in one call:
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
// workingDir + autoInstall, done in one step
comp, err := composer.QuickSetup("/path/to/php/project", true)
if err != nil {
log.Fatalf("Quick setup failed: %v", err)
}
// Instance is ready
ver, _ := comp.GetVersion()
fmt.Printf("✅ Composer ready, version: %s\n", ver)
}Want to observe the install process? Use QuickSetupWithProgress with a progress callback:
comp, installResult, err := composer.QuickSetupWithProgress(
"/path/to/php/project",
func(stage string, percent int) {
fmt.Printf("[%s] %d%%\n", stage, percent)
},
)🧩 Underlying components
The auto-install chain is powered by two underlying packages, which you can also use independently:
Detector
Package path: github.com/scagogogo/composer-skills/pkg/detector
Cross-OS lookup for installed Composer: scans PATH, common install paths, COMPOSER environment variable, and uses which/where as a fallback.
d := detector.NewDetector()
if d.IsInstalled() {
path, _ := d.Detect()
fmt.Printf("Composer located at: %s\n", path)
} else {
fmt.Println("Composer not detected")
}See Detector docs.
Installer
Package path: github.com/scagogogo/composer-skills/pkg/installer
Handles actual download and installation, with Linux distro detection, macOS brew, Windows phar wrapping, and can install PHP along the way.
inst := installer.NewInstaller(installer.SmartConfig())
if err := inst.Install(); err != nil {
log.Fatal(err)
}Two common configurations:
installer.DefaultConfig()— Default configuration.installer.SmartConfig()— Smart configuration: automatically picks the best install method per platform (brew/apt/direct download).
See Installer docs.
🖥️ Smart defaults: per-platform selection
The installer takes different paths depending on the runtime platform — this is the "smart default":
| Platform | Primary strategy | Fallback strategy |
|---|---|---|
| 🐧 Linux | Distro package manager (apt/dnf/pacman) | Download composer.phar + wrapper script |
| 🍎 macOS | brew install composer | Download composer.phar |
| 🪟 Windows | Download composer.phar + .cmd wrapper | Same as primary |
On Linux, DetectLinuxDistro() parses /etc/os-release to decide between apt, dnf, or others.
Need sudo?
Global installation via package manager may require permissions. The installer provides a useSudo parameter to control whether to prefix with sudo. CI containers usually run as root, so no sudo is needed.
⏱️ Disabling auto-install
In some scenarios (production, strict auditing) you don't want the program installing things silently. Turn off AutoInstall:
options := composer.DefaultOptions()
options.AutoInstall = false
comp, err := composer.New(options)
// If Composer doesn't exist, err will tell you🧭 Next steps
- 📡 Detector docs — detection paths, environment variables, cross-platform details.
- 📥 Installer docs — configuration, progress callbacks, distro detection.
- 🖥️ Cross-platform support — support matrix for the three major platforms.
- 🔄 CI/CD pipeline — enjoy auto-install in GitHub Actions.