🛠️ Run
Executes an arbitrary Composer command and returns the output; the core method of the SDK. It uses a 10-minute timeout by default.
When to use
Use this when the SDK does not provide a dedicated wrapper for a Composer subcommand — run the raw command directly with Run. It is the thinnest wrapper over the composer executable, and the arguments are the command-line arguments.
Signature
go
func (c *Composer) Run(args ...string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
args | ...string | Command arguments; the first argument is the Composer subcommand, e.g. show, require |
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | The standard output of the command (including merged stderr) |
| Second return value | error | Returned when the command fails; the error message includes the output content |
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatalf("init failed: %v", err)
}
// Run composer show
output, err := comp.Run("show")
if err != nil {
log.Fatalf("command failed: %v", err)
}
fmt.Println(output)
// Run a command with arguments
_, err = comp.Run("require", "symfony/console", "--dev")
if err != nil {
log.Fatalf("install package failed: %v", err)
}
}Advanced
- For a custom timeout, use RunWithTimeout.
- For cancellation control, use RunWithContext.
- Prefer dedicated convenience methods (e.g. GetInstalledPackageNames), which already handle output parsing.