🚀 QuickSetup
Detects, installs, and initializes Composer in one step, returning a ready-to-use *Composer instance. It is the most convenient entry point.
When to use
Use this when you want to complete all environment preparation in a single line of code without manually assembling Options and calling EnsureInstalled. It is especially suited for the startup entry of scripts and CLI tools.
Signature
go
func QuickSetup(workingDir string, autoInstall bool) (*Composer, error)Parameters
| Parameter | Type | Description |
|---|---|---|
workingDir | string | The working directory path; pass an empty string to use the current directory |
autoInstall | bool | Whether to auto-install Composer when it is not detected |
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | *Composer | The ready Composer instance |
| Second return value | error | Returned when construction or installation fails |
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.QuickSetup("/path/to/project", true)
if err != nil {
log.Fatalf("quick setup failed: %v", err)
}
fmt.Println("Composer environment ready ✅")
// You can now use comp directly to perform various operations
}Advanced
- For an installation progress callback, use
QuickSetupWithProgress. - For fine-grained control over each option, use New + DefaultOptions.
- It internally calls EnsureInstalled, so with
autoInstall=trueit always ensures availability.