Skip to content

🧹 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) error

Parameters ​

ParameterTypeDescription
namestringThe name of the script to remove

Return value ​

  • error: returned when reading or writing composer.json fails.

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 → delete once from Scripts and once from ScriptsDescriptions → 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 (returns map[string]interface{}).

Released under the MIT License