🧹 RemoveScript
Removes the script with the specified name and its description from composer.json.
When to use
Use this when you need to clean up Composer lifecycle scripts or custom scripts that are no longer needed. This method cleans up the corresponding entry in both the scripts section and the scripts-descriptions section.
Signature
go
func (c *Composer) RemoveScript(name string) errorParameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the script to remove |
Return value
error: returned when reading or writingcomposer.jsonfails.
Example
go
package main
import (
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatal(err)
}
if err := comp.RemoveScript("post-install-cmd"); err != nil {
log.Fatalf("remove script failed: %v", err)
}
}Advanced
- 🔄 Internal flow:
ReadComposerJSON→deleteonce fromScriptsand once fromScriptsDescriptions→WriteComposerJSON. - ⚠️ When the script does not exist or the map is
nil, the method is a safe no-op and does not error. - ➕ The corresponding add method is
AddScript. - 📋 To query existing scripts, use
GetScripts(returnsmap[string]interface{}).