Skip to content

📊 GetConfigStructured

Gets all Composer configuration items for the current project and parses the text output into the structured *ConfigResult. Equivalent to running composer config --list and automatically parsing it.

When to use

Use it when you need to iterate over configuration items programmatically, filter by key, or perform bulk comparisons. Compared to the raw string returned by ListConfig, the structured result is more suitable for machine processing.

Signature

go
func (c *Composer) GetConfigStructured() (*ConfigResult, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return value*ConfigResultParsed configuration result
Second return valueerrorReturned when execution fails

Fields of ConfigResult and ConfigItem:

FieldTypeDescription
ConfigResult.Items[]ConfigItemList of all configuration items
ConfigItem.KeystringConfiguration item name
ConfigItem.ValuestringConfiguration item value
ConfigItem.SourcestringConfiguration source (usually empty during parsing)

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

	result, err := comp.GetConfigStructured()
	if err != nil {
		log.Fatalf("failed to get configuration: %v", err)
	}

	for _, item := range result.Items {
		fmt.Printf("%s = %s\n", item.Key, item.Value)
	}
}

Advanced

  • The underlying parser function ParseConfigList(output string) *ConfigResult can be used independently to parse any composer config --list text.
  • For the raw text only, use ListConfig.
  • For a single configuration item only, use GetConfigWithGlobal.

Released under the MIT License