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>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
// Package lemcmd provides CLI commands for the LEM binary.
|
|
// Commands register through the Core framework's cli.WithCommands lifecycle.
|
|
package lemcmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"forge.lthn.ai/core/cli/pkg/cli"
|
|
)
|
|
|
|
// AddLEMCommands registers all LEM command groups on the root command.
|
|
func AddLEMCommands(root *cli.Command) {
|
|
addScoreCommands(root)
|
|
addGenCommands(root)
|
|
addDataCommands(root)
|
|
addExportCommands(root)
|
|
addMonCommands(root)
|
|
addInfraCommands(root)
|
|
}
|
|
|
|
// envOr returns the environment variable value, or the fallback if not set.
|
|
func envOr(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
// intEnvOr returns the environment variable value parsed as int, or the fallback.
|
|
func intEnvOr(key string, fallback int) int {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
return fallback
|
|
}
|
|
var n int
|
|
fmt.Sscanf(v, "%d", &n)
|
|
if n == 0 {
|
|
return fallback
|
|
}
|
|
return n
|
|
}
|
|
|
|
// expandHome expands a leading ~/ to the user's home directory.
|
|
func expandHome(path string) string {
|
|
if strings.HasPrefix(path, "~/") {
|
|
home, err := os.UserHomeDir()
|
|
if err == nil {
|
|
return filepath.Join(home, path[2:])
|
|
}
|
|
}
|
|
return path
|
|
}
|