📦 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 value | Type | Description |
|---|---|---|
| First return value | *ComposerJsonInfo | Struct pointer containing the project's basic information and dependency list |
| Second return value | error | Returned 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.jsoncontent, useReadComposerJSON()to get a*ComposerJSON. - To get a summary of project dependencies (including direct/indirect), use
GetProjectDependencies(). - Combine with
ListScriptsto also view the scripts defined in the project.