⌨️ GetScripts
Gets the script mapping (the scripts field) defined in composer.json.
When to use
Use this when you need to list the available Composer scripts in a project, or to decide which script event to trigger from within a program. It reads composer.json directly and does not execute Composer commands.
Signature
go
func (c *Composer) GetScripts() (map[string]interface{}, error)Parameters
This method takes no parameters.
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | map[string]interface{} | Mapping from script event names to their definitions, e.g. post-install-cmd → command list |
| Second return value | error | Returned when reading or parsing composer.json fails |
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("Initialization failed: %v", err)
}
scripts, err := comp.GetScripts()
if err != nil {
log.Fatalf("Failed to get scripts: %v", err)
}
for event, def := range scripts {
fmt.Printf("%s => %v\n", event, def)
}
}Advanced
- To actually execute a script, use
RunScriptorExecuteScript. - To list scripts as text, use
ListScripts. - To add or remove scripts programmatically, use
AddScript/RemoveScript.