Skip to content

🧭 GetEnvironmentInfo

Gets all Composer configuration items and returns a key-value map. Equivalent to running composer config --list and parsing it line by line.

When to use

Use it when you need to inspect the currently effective Composer configuration (cache directory, home directory, repositories, stability, etc.) for diagnostics or logging.

Signature

go
func (c *Composer) GetEnvironmentInfo() (map[string]string, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return valuemap[string]stringConfiguration key-value pairs; key is the configuration name, value is the configuration value
Second return valueerrorReturned when command execution or parsing fails

Parsing rules

The output is split by lines, and each line is split into a key-value pair by :. Lines that cannot be split by : are skipped.

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

	info, err := comp.GetEnvironmentInfo()
	if err != nil {
		log.Fatalf("failed to get environment info: %v", err)
	}

	for k, v := range info {
		fmt.Printf("%s = %s\n", k, v)
	}
}

Advanced

  • For the value of a single environment variable, use the lighter-weight GetEnvVariable.
  • To set an environment variable, use SetEnvVariable.
  • For a structured configuration list, refer to GetConfigStructured() (located in result_types.go).

Released under the MIT License