Skip to content

🛠️ 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 ​

ParameterTypeDescription
args...stringCommand arguments; the first argument is the Composer subcommand, e.g. show, require

Return value ​

Return valueTypeDescription
First return valuestringThe standard output of the command (including merged stderr)
Second return valueerrorReturned 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 ​

Released under the MIT License