Skip to content

📋 CheckPlatformReqsStructured

Checks platform requirements and returns structured results with status markers (ok/missing/mismatch).

When to use

Use when you need to precisely distinguish "missing extension" from "version mismatch" in code and give different prompts accordingly.

Signature

go
func (c *Composer) CheckPlatformReqsStructured() (*PlatformCheckResult, error)

Parameters

ParameterTypeDescription
NoneThis method takes no parameters

Return value

  • *PlatformCheckResult: Platform requirements check result, including each requirement and an overall OK flag
  • error: Returned when execution or parsing fails
go
type PlatformCheckResult struct {
    Requirements []PlatformRequirement `json:"requirements"`
    OK           bool                  `json:"ok"`
}

type PlatformRequirement struct {
    Package  string `json:"package"`
    Version  string `json:"version,omitempty"`
    Status   string `json:"status"` // "ok", "missing", "mismatch"
    Required string `json:"required,omitempty"`
}

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.Fatal(err)
    }

    result, err := comp.CheckPlatformReqsStructured()
    if err != nil {
        log.Fatalf("platform requirements check failed: %v", err)
    }

    fmt.Printf("Overall passed: %v\n", result.OK)
    for _, req := range result.Requirements {
        fmt.Printf("%s %s -> %s\n", req.Package, req.Required, req.Status)
    }
}

Advanced

  • This method runs composer check-platform-reqs --format=json and parses it via ParsePlatformCheckResult
  • When Status is neither ok nor success, OK is set to false
  • If you only need an Available boolean check, use the simpler CheckPlatform
  • The parser ParsePlatformCheckResult can be used independently for custom command output

Released under the MIT License