Replace passthrough() + stdlib flag.FlagSet anti-pattern with proper cobra integration. Every Run* function now takes a typed *Opts struct and returns error. Flags registered via cli.StringFlag/IntFlag/etc. Commands participate in Core lifecycle with full cobra flag parsing. - 6 command groups: gen, score, data, export, infra, mon - 25 commands converted, 0 passthrough() calls remain - Delete passthrough() helper from lem.go - Update export_test.go to use ExportOpts struct Co-Authored-By: Virgil <virgil@lethean.io>
94 lines
2.6 KiB
Go
94 lines
2.6 KiB
Go
package lem
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// InventoryOpts holds configuration for the inventory command.
|
|
type InventoryOpts struct {
|
|
DB string // DuckDB database path (defaults to LEM_DB env)
|
|
}
|
|
|
|
// RunInventory shows row counts and summary stats for all tables in the DuckDB database.
|
|
func RunInventory(cfg InventoryOpts) error {
|
|
if cfg.DB == "" {
|
|
cfg.DB = os.Getenv("LEM_DB")
|
|
}
|
|
if cfg.DB == "" {
|
|
return fmt.Errorf("--db or LEM_DB required")
|
|
}
|
|
|
|
db, err := OpenDB(cfg.DB)
|
|
if err != nil {
|
|
return fmt.Errorf("open db: %w", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
counts, err := db.TableCounts()
|
|
if err != nil {
|
|
return fmt.Errorf("table counts: %w", err)
|
|
}
|
|
|
|
fmt.Printf("LEM Database Inventory (%s)\n", cfg.DB)
|
|
fmt.Println("============================================================")
|
|
|
|
grandTotal := 0
|
|
for table, count := range counts {
|
|
detail := ""
|
|
|
|
switch table {
|
|
case "golden_set":
|
|
pct := float64(count) / float64(targetTotal) * 100
|
|
detail = fmt.Sprintf(" (%.1f%% of %d target)", pct, targetTotal)
|
|
case "training_examples":
|
|
var sources int
|
|
db.conn.QueryRow("SELECT COUNT(DISTINCT source) FROM training_examples").Scan(&sources)
|
|
detail = fmt.Sprintf(" (%d sources)", sources)
|
|
case "prompts":
|
|
var domains, voices int
|
|
db.conn.QueryRow("SELECT COUNT(DISTINCT domain) FROM prompts").Scan(&domains)
|
|
db.conn.QueryRow("SELECT COUNT(DISTINCT voice) FROM prompts").Scan(&voices)
|
|
detail = fmt.Sprintf(" (%d domains, %d voices)", domains, voices)
|
|
case "gemini_responses":
|
|
rows, _ := db.conn.Query("SELECT source_model, count(*) FROM gemini_responses GROUP BY source_model")
|
|
if rows != nil {
|
|
var parts []string
|
|
for rows.Next() {
|
|
var model string
|
|
var n int
|
|
rows.Scan(&model, &n)
|
|
parts = append(parts, fmt.Sprintf("%s: %d", model, n))
|
|
}
|
|
rows.Close()
|
|
if len(parts) > 0 {
|
|
detail = fmt.Sprintf(" (%s)", joinStrings(parts, ", "))
|
|
}
|
|
}
|
|
case "benchmark_results":
|
|
var sources int
|
|
db.conn.QueryRow("SELECT COUNT(DISTINCT source) FROM benchmark_results").Scan(&sources)
|
|
detail = fmt.Sprintf(" (%d categories)", sources)
|
|
}
|
|
|
|
fmt.Printf(" %-25s %8d%s\n", table, count, detail)
|
|
grandTotal += count
|
|
}
|
|
|
|
fmt.Printf(" %-25s\n", "────────────────────────────────────────")
|
|
fmt.Printf(" %-25s %8d\n", "TOTAL", grandTotal)
|
|
|
|
return nil
|
|
}
|
|
|
|
func joinStrings(parts []string, sep string) string {
|
|
var result strings.Builder
|
|
for i, p := range parts {
|
|
if i > 0 {
|
|
result.WriteString(sep)
|
|
}
|
|
result.WriteString(p)
|
|
}
|
|
return result.String()
|
|
}
|