📦 InstallComposerViaPackageManager
Installs Composer via the system's native package manager.
When to Use
Use this when you are on Linux and want to install Composer with apt/dnf/yum/pacman/apk/zypper rather than downloading the phar directly. 🐧
Signature
go
func InstallComposerViaPackageManager(distro *DistroInfo, useSudo bool) (bool, error)Parameters
| Parameter | Type | Description |
|---|---|---|
distro | *DistroInfo | Distribution info, typically obtained from DetectLinuxDistro |
useSudo | bool | Whether to prefix the command with sudo |
Return Value
bool: Whether installation was attempted (truewhen a matching package manager is found,falseotherwise). 🎯error: Returns a wrapped error on command execution failure;nilwhen not attempted. ⚠️
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/installer"
)
func main() {
distro, err := installer.DetectLinuxDistro()
if err != nil {
log.Fatalf("failed to detect distro: %v", err)
}
attempted, err := installer.InstallComposerViaPackageManager(distro, true)
if !attempted {
fmt.Println("no package manager available")
return
}
if err != nil {
log.Fatalf("installation failed: %v", err)
}
fmt.Println("installed via package manager")
}Advanced
- A return of
attempted=falsemeans the distro has no known package manager; the caller should fall back to direct download. 🔄 - Called by
Installer.InstallandSmartInstallerwhenPreferPackageManageris set. 🔗 - Package names and command arguments vary across distros (e.g. pacman uses
-S --noconfirm); these are handled internally. 🛠️