Skip to content

📋 ListConfig

Lists all Composer configuration items and their values for the current project. Equivalent to running composer config --list.

When to use

Use this when you need to view all the effective configuration of the current project at once (the merged result of default, project, and global values). Suitable for outputting a snapshot of the current environment in debugging scripts or diagnostic tools.

Signature

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

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return valuestringThe raw text output of composer config --list
Second return valueerrorReturned on execution failure; the error message is wrapped by fmt.Errorf as "failed to list config"

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

	output, err := comp.ListConfig()
	if err != nil {
		log.Fatalf("Failed to list config: %v", err)
	}
	fmt.Println(output)
}

Advanced

  • To distinguish global configuration from project configuration, use ListConfigWithGlobal(global bool).
  • To process items one by one in a program, use the structured version GetConfigStructured, which returns a *ConfigResult.
  • To read a single configuration item, use GetConfigWithGlobal.

Released under the MIT License