Skip to content

📦 GetProjectInfo

Gets the basic information of the current project (name, description, type, dependencies) and returns a structured *ComposerJsonInfo, equivalent to running composer config --list --json and parsing the result.

When to use

Use this when you need to read the composer.json summary information of a project in a structured way from within a program. The return value is a struct, making it easy to access fields directly without parsing text output yourself.

Signature

go
func (c *Composer) GetProjectInfo() (*ComposerJsonInfo, error)

The ComposerJsonInfo struct is defined as follows:

go
type ComposerJsonInfo struct {
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Type        string            `json:"type"`
	Require     map[string]string `json:"require"`
	RequireDev  map[string]string `json:"require-dev"`
}

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return value*ComposerJsonInfoStruct pointer containing the project's basic information and dependency list
Second return valueerrorReturned when an error occurs during retrieval or parsing; nil indicates 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("Initialization failed: %v", err)
	}

	info, err := comp.GetProjectInfo()
	if err != nil {
		log.Fatalf("Failed to get project info: %v", err)
	}

	fmt.Printf("Project name: %s\n", info.Name)
	fmt.Printf("Project description: %s\n", info.Description)
	fmt.Printf("Project type: %s\n", info.Type)
	fmt.Printf("Dependency count: %d\n", len(info.Require))
}

Advanced

  • To read the more complete composer.json content, use ReadComposerJSON() to get a *ComposerJSON.
  • To get a summary of project dependencies (including direct/indirect), use GetProjectDependencies().
  • Combine with ListScripts to also view the scripts defined in the project.

Released under the MIT License