feat: add N14 selector report CLI
This commit is contained in:
62
cmd/uia-selector-report/main.go
Normal file
62
cmd/uia-selector-report/main.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"isphere-ai-bridge/internal/uiaselector"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Exit(Run(os.Args[1:], os.Stdout, os.Stderr))
|
||||
}
|
||||
|
||||
func Run(args []string, stdout io.Writer, stderr io.Writer) int {
|
||||
flags := flag.NewFlagSet("uia-selector-report", flag.ContinueOnError)
|
||||
flags.SetOutput(stderr)
|
||||
dumpPath := flags.String("dump", "", "UIA dump JSON path")
|
||||
outJSON := flags.String("out-json", "", "JSON report output path")
|
||||
outMD := flags.String("out-md", "", "Markdown report output path")
|
||||
strict := flags.Bool("strict", false, "return non-zero for unmatched, ambiguous, or invalid selector reports")
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return uiaselector.StrictExitReportGenerationFailure
|
||||
}
|
||||
if *dumpPath == "" {
|
||||
fmt.Fprintln(stderr, "missing -dump")
|
||||
return uiaselector.StrictExitReportGenerationFailure
|
||||
}
|
||||
|
||||
root, err := uiaselector.LoadDumpFile(*dumpPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "load dump: %v\n", err)
|
||||
return uiaselector.StrictExitReportGenerationFailure
|
||||
}
|
||||
report := uiaselector.RunCatalogReport(*dumpPath, root, uiaselector.DefaultCatalog(), time.Now().UTC())
|
||||
if *outJSON != "" {
|
||||
if err := uiaselector.WriteReportJSON(report, *outJSON); err != nil {
|
||||
fmt.Fprintf(stderr, "write JSON report: %v\n", err)
|
||||
return uiaselector.StrictExitReportGenerationFailure
|
||||
}
|
||||
}
|
||||
if *outMD != "" {
|
||||
if err := uiaselector.WriteReportMarkdown(report, *outMD); err != nil {
|
||||
fmt.Fprintf(stderr, "write Markdown report: %v\n", err)
|
||||
return uiaselector.StrictExitReportGenerationFailure
|
||||
}
|
||||
}
|
||||
|
||||
code := uiaselector.StrictExitCode(report)
|
||||
if *strict && code != uiaselector.StrictExitOK {
|
||||
fmt.Fprintf(stderr, "strict report check failed with code %d\n", code)
|
||||
return code
|
||||
}
|
||||
if !report.OK {
|
||||
fmt.Fprintf(stderr, "report generation failed: %#v\n", report.Error)
|
||||
return uiaselector.StrictExitReportGenerationFailure
|
||||
}
|
||||
fmt.Fprintf(stdout, "N14 selector report generated: catalog=%d matched=%d unmatched=%d ambiguous=%d\n", report.CatalogSize, report.MatchedCount, report.UnmatchedCount, report.AmbiguousCount)
|
||||
return uiaselector.StrictExitOK
|
||||
}
|
||||
Reference in New Issue
Block a user