Skip to content

📚 ListScripts

Lists all scripts defined in composer.json, equivalent to running composer run-script --list.

When to use

Use this when you need to see which scripts are available in the current project, or to confirm a script name before running it. The output is Composer's standard text list.

Signature

go
func (c *Composer) ListScripts() (string, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return valuestringThe standard output text of the full script list
Second return valueerrorReturned when an error occurs while listing scripts; nil on success

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)
	}

	output, err := comp.ListScripts()
	if err != nil {
		log.Fatalf("list scripts failed: %v", err)
	}

	fmt.Println("Available scripts:")
	fmt.Println(output)
}

Advanced

  • To read script definitions as map[string]interface{}, use the GetScripts() method, which is convenient for programmatic processing.
  • Once you have confirmed the script name, you can trigger execution with RunScript (with arguments) or ExecuteScript (without arguments).
  • To add or remove script definitions, use the AddScript / RemoveScript methods.

Released under the MIT License