2026-01-30 00:22:47 +00:00
|
|
|
package gocmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
|
2026-01-30 10:32:05 +00:00
|
|
|
"github.com/host-uk/core/pkg/cli"
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
"github.com/host-uk/core/pkg/i18n"
|
2026-01-30 00:47:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
2026-01-30 00:22:47 +00:00
|
|
|
)
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
var (
|
|
|
|
|
testCoverage bool
|
|
|
|
|
testPkg string
|
|
|
|
|
testRun string
|
|
|
|
|
testShort bool
|
|
|
|
|
testRace bool
|
|
|
|
|
testJSON bool
|
|
|
|
|
testVerbose bool
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func addGoTestCommand(parent *cobra.Command) {
|
|
|
|
|
testCmd := &cobra.Command{
|
|
|
|
|
Use: "test",
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
Short: i18n.T("cmd.go.test.short"),
|
|
|
|
|
Long: i18n.T("cmd.go.test.long"),
|
2026-01-30 00:47:54 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
return runGoTest(testCoverage, testPkg, testRun, testShort, testRace, testJSON, testVerbose)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
testCmd.Flags().BoolVar(&testCoverage, "coverage", false, i18n.T("common.flag.coverage"))
|
|
|
|
|
testCmd.Flags().StringVar(&testPkg, "pkg", "", i18n.T("common.flag.pkg"))
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
testCmd.Flags().StringVar(&testRun, "run", "", i18n.T("cmd.go.test.flag.run"))
|
|
|
|
|
testCmd.Flags().BoolVar(&testShort, "short", false, i18n.T("cmd.go.test.flag.short"))
|
|
|
|
|
testCmd.Flags().BoolVar(&testRace, "race", false, i18n.T("cmd.go.test.flag.race"))
|
|
|
|
|
testCmd.Flags().BoolVar(&testJSON, "json", false, i18n.T("cmd.go.test.flag.json"))
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
testCmd.Flags().BoolVarP(&testVerbose, "verbose", "v", false, i18n.T("common.flag.verbose"))
|
2026-01-30 00:47:54 +00:00
|
|
|
|
|
|
|
|
parent.AddCommand(testCmd)
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runGoTest(coverage bool, pkg, run string, short, race, jsonOut, verbose bool) error {
|
|
|
|
|
if pkg == "" {
|
|
|
|
|
pkg = "./..."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args := []string{"test"}
|
|
|
|
|
|
|
|
|
|
if coverage {
|
|
|
|
|
args = append(args, "-cover")
|
|
|
|
|
} else {
|
|
|
|
|
args = append(args, "-cover")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if run != "" {
|
|
|
|
|
args = append(args, "-run", run)
|
|
|
|
|
}
|
|
|
|
|
if short {
|
|
|
|
|
args = append(args, "-short")
|
|
|
|
|
}
|
|
|
|
|
if race {
|
|
|
|
|
args = append(args, "-race")
|
|
|
|
|
}
|
|
|
|
|
if verbose {
|
|
|
|
|
args = append(args, "-v")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args = append(args, pkg)
|
|
|
|
|
|
|
|
|
|
if !jsonOut {
|
2026-01-30 11:44:45 +00:00
|
|
|
fmt.Printf("%s %s\n", dimStyle.Render(i18n.T("common.label.test")), i18n.T("common.progress.running", map[string]any{"Task": "tests"}))
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
fmt.Printf(" %s %s\n", dimStyle.Render(i18n.T("common.label.package")), pkg)
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command("go", args...)
|
|
|
|
|
cmd.Env = append(os.Environ(), "MACOSX_DEPLOYMENT_TARGET=26.0", "CGO_ENABLED=0")
|
|
|
|
|
cmd.Dir, _ = os.Getwd()
|
|
|
|
|
|
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
|
|
|
outputStr := string(output)
|
|
|
|
|
|
|
|
|
|
// Filter linker warnings
|
|
|
|
|
lines := strings.Split(outputStr, "\n")
|
|
|
|
|
var filtered []string
|
|
|
|
|
for _, line := range lines {
|
|
|
|
|
if !strings.Contains(line, "ld: warning:") {
|
|
|
|
|
filtered = append(filtered, line)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
outputStr = strings.Join(filtered, "\n")
|
|
|
|
|
|
|
|
|
|
// Parse results
|
|
|
|
|
passed, failed, skipped := parseTestResults(outputStr)
|
|
|
|
|
cov := parseOverallCoverage(outputStr)
|
|
|
|
|
|
|
|
|
|
if jsonOut {
|
|
|
|
|
fmt.Printf(`{"passed":%d,"failed":%d,"skipped":%d,"coverage":%.1f,"exit_code":%d}`,
|
|
|
|
|
passed, failed, skipped, cov, cmd.ProcessState.ExitCode())
|
|
|
|
|
fmt.Println()
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print filtered output if verbose or failed
|
|
|
|
|
if verbose || err != nil {
|
|
|
|
|
fmt.Println(outputStr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Summary
|
|
|
|
|
if err == nil {
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
fmt.Printf(" %s %s\n", successStyle.Render("✓"), i18n.T("common.count.passed", map[string]interface{}{"Count": passed}))
|
2026-01-30 00:22:47 +00:00
|
|
|
} else {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf(" %s %s\n", errorStyle.Render("✗"), i18n.T("cmd.go.test.passed_failed", map[string]interface{}{"Passed": passed, "Failed": failed}))
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if cov > 0 {
|
2026-01-30 10:32:05 +00:00
|
|
|
fmt.Printf("\n %s %s\n", cli.ProgressLabel(i18n.T("cmd.go.test.coverage")), cli.FormatCoverage(cov))
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err == nil {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf("\n%s\n", successStyle.Render(i18n.T("cmd.go.test.all_passed")))
|
2026-01-30 00:22:47 +00:00
|
|
|
} else {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf("\n%s\n", errorStyle.Render(i18n.T("cmd.go.test.some_failed")))
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseTestResults(output string) (passed, failed, skipped int) {
|
|
|
|
|
passRe := regexp.MustCompile(`(?m)^ok\s+`)
|
|
|
|
|
failRe := regexp.MustCompile(`(?m)^FAIL\s+`)
|
|
|
|
|
skipRe := regexp.MustCompile(`(?m)^\?\s+`)
|
|
|
|
|
|
|
|
|
|
passed = len(passRe.FindAllString(output, -1))
|
|
|
|
|
failed = len(failRe.FindAllString(output, -1))
|
|
|
|
|
skipped = len(skipRe.FindAllString(output, -1))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseOverallCoverage(output string) float64 {
|
|
|
|
|
re := regexp.MustCompile(`coverage:\s+([\d.]+)%`)
|
|
|
|
|
matches := re.FindAllStringSubmatch(output, -1)
|
|
|
|
|
if len(matches) == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var total float64
|
|
|
|
|
for _, m := range matches {
|
|
|
|
|
var cov float64
|
|
|
|
|
fmt.Sscanf(m[1], "%f", &cov)
|
|
|
|
|
total += cov
|
|
|
|
|
}
|
|
|
|
|
return total / float64(len(matches))
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
var (
|
|
|
|
|
covPkg string
|
|
|
|
|
covHTML bool
|
|
|
|
|
covOpen bool
|
|
|
|
|
covThreshold float64
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func addGoCovCommand(parent *cobra.Command) {
|
|
|
|
|
covCmd := &cobra.Command{
|
|
|
|
|
Use: "cov",
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
Short: i18n.T("cmd.go.cov.short"),
|
|
|
|
|
Long: i18n.T("cmd.go.cov.long"),
|
2026-01-30 00:47:54 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
pkg := covPkg
|
|
|
|
|
if pkg == "" {
|
|
|
|
|
// Auto-discover packages with tests
|
|
|
|
|
pkgs, err := findTestPackages(".")
|
|
|
|
|
if err != nil {
|
2026-01-30 11:44:45 +00:00
|
|
|
return fmt.Errorf("%s: %w", i18n.T("common.error.failed", map[string]any{"Action": "discover test packages"}), err)
|
2026-01-30 00:47:54 +00:00
|
|
|
}
|
|
|
|
|
if len(pkgs) == 0 {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
return fmt.Errorf(i18n.T("cmd.go.cov.error.no_packages"))
|
2026-01-30 00:47:54 +00:00
|
|
|
}
|
|
|
|
|
pkg = strings.Join(pkgs, " ")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create temp file for coverage data
|
|
|
|
|
covFile, err := os.CreateTemp("", "coverage-*.out")
|
2026-01-30 00:22:47 +00:00
|
|
|
if err != nil {
|
2026-01-30 11:44:45 +00:00
|
|
|
return fmt.Errorf("%s: %w", i18n.T("common.error.failed", map[string]any{"Action": "create coverage file"}), err)
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
2026-01-30 00:47:54 +00:00
|
|
|
covPath := covFile.Name()
|
|
|
|
|
covFile.Close()
|
|
|
|
|
defer os.Remove(covPath)
|
|
|
|
|
|
2026-01-30 11:44:45 +00:00
|
|
|
fmt.Printf("%s %s\n", dimStyle.Render(i18n.T("common.label.coverage")), i18n.T("common.progress.running", map[string]any{"Task": "tests with coverage"}))
|
2026-01-30 00:47:54 +00:00
|
|
|
// Truncate package list if too long for display
|
|
|
|
|
displayPkg := pkg
|
|
|
|
|
if len(displayPkg) > 60 {
|
|
|
|
|
displayPkg = displayPkg[:57] + "..."
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
fmt.Printf(" %s %s\n", dimStyle.Render(i18n.T("common.label.package")), displayPkg)
|
2026-01-30 00:47:54 +00:00
|
|
|
fmt.Println()
|
2026-01-30 00:22:47 +00:00
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// Run tests with coverage
|
|
|
|
|
// We need to split pkg into individual arguments if it contains spaces
|
|
|
|
|
pkgArgs := strings.Fields(pkg)
|
|
|
|
|
cmdArgs := append([]string{"test", "-coverprofile=" + covPath, "-covermode=atomic"}, pkgArgs...)
|
2026-01-30 00:22:47 +00:00
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
goCmd := exec.Command("go", cmdArgs...)
|
|
|
|
|
goCmd.Env = append(os.Environ(), "MACOSX_DEPLOYMENT_TARGET=26.0")
|
|
|
|
|
goCmd.Stdout = os.Stdout
|
|
|
|
|
goCmd.Stderr = os.Stderr
|
2026-01-30 00:22:47 +00:00
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
testErr := goCmd.Run()
|
2026-01-30 00:22:47 +00:00
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// Get coverage percentage
|
|
|
|
|
coverCmd := exec.Command("go", "tool", "cover", "-func="+covPath)
|
|
|
|
|
covOutput, err := coverCmd.Output()
|
|
|
|
|
if err != nil {
|
|
|
|
|
if testErr != nil {
|
|
|
|
|
return testErr
|
|
|
|
|
}
|
2026-01-30 11:44:45 +00:00
|
|
|
return fmt.Errorf("%s: %w", i18n.T("common.error.failed", map[string]any{"Action": "get coverage"}), err)
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// Parse total coverage from last line
|
|
|
|
|
lines := strings.Split(strings.TrimSpace(string(covOutput)), "\n")
|
|
|
|
|
var totalCov float64
|
|
|
|
|
if len(lines) > 0 {
|
|
|
|
|
lastLine := lines[len(lines)-1]
|
|
|
|
|
// Format: "total: (statements) XX.X%"
|
|
|
|
|
if strings.Contains(lastLine, "total:") {
|
|
|
|
|
parts := strings.Fields(lastLine)
|
|
|
|
|
if len(parts) >= 3 {
|
|
|
|
|
covStr := strings.TrimSuffix(parts[len(parts)-1], "%")
|
|
|
|
|
fmt.Sscanf(covStr, "%f", &totalCov)
|
|
|
|
|
}
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// Print coverage summary
|
|
|
|
|
fmt.Println()
|
2026-01-30 10:32:05 +00:00
|
|
|
fmt.Printf(" %s %s\n", cli.ProgressLabel(i18n.T("label.total")), cli.FormatCoverage(totalCov))
|
2026-01-30 00:47:54 +00:00
|
|
|
|
|
|
|
|
// Generate HTML if requested
|
|
|
|
|
if covHTML || covOpen {
|
|
|
|
|
htmlPath := "coverage.html"
|
|
|
|
|
htmlCmd := exec.Command("go", "tool", "cover", "-html="+covPath, "-o="+htmlPath)
|
|
|
|
|
if err := htmlCmd.Run(); err != nil {
|
2026-01-30 11:44:45 +00:00
|
|
|
return fmt.Errorf("%s: %w", i18n.T("common.error.failed", map[string]any{"Action": "generate HTML"}), err)
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf(" %s %s\n", dimStyle.Render(i18n.T("cmd.go.cov.html_label")), htmlPath)
|
2026-01-30 00:47:54 +00:00
|
|
|
|
|
|
|
|
if covOpen {
|
|
|
|
|
// Open in browser
|
|
|
|
|
var openCmd *exec.Cmd
|
|
|
|
|
switch {
|
|
|
|
|
case exec.Command("which", "open").Run() == nil:
|
|
|
|
|
openCmd = exec.Command("open", htmlPath)
|
|
|
|
|
case exec.Command("which", "xdg-open").Run() == nil:
|
|
|
|
|
openCmd = exec.Command("xdg-open", htmlPath)
|
|
|
|
|
default:
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf(" %s\n", dimStyle.Render(i18n.T("cmd.go.cov.open_manually")))
|
2026-01-30 00:47:54 +00:00
|
|
|
}
|
|
|
|
|
if openCmd != nil {
|
|
|
|
|
openCmd.Run()
|
|
|
|
|
}
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// Check threshold
|
|
|
|
|
if covThreshold > 0 && totalCov < covThreshold {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf("\n%s\n", errorStyle.Render(i18n.T("cmd.go.cov.below_threshold", map[string]interface{}{
|
|
|
|
|
"Actual": fmt.Sprintf("%.1f", totalCov),
|
|
|
|
|
"Threshold": fmt.Sprintf("%.1f", covThreshold),
|
|
|
|
|
})))
|
|
|
|
|
return fmt.Errorf(i18n.T("cmd.go.cov.error.below_threshold"))
|
2026-01-30 00:47:54 +00:00
|
|
|
}
|
2026-01-30 00:22:47 +00:00
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
if testErr != nil {
|
|
|
|
|
return testErr
|
|
|
|
|
}
|
2026-01-30 00:22:47 +00:00
|
|
|
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
fmt.Printf("\n%s\n", successStyle.Render(i18n.T("cli.ok")))
|
2026-01-30 00:47:54 +00:00
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
covCmd.Flags().StringVar(&covPkg, "pkg", "", i18n.T("common.flag.pkg"))
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
covCmd.Flags().BoolVar(&covHTML, "html", false, i18n.T("cmd.go.cov.flag.html"))
|
|
|
|
|
covCmd.Flags().BoolVar(&covOpen, "open", false, i18n.T("cmd.go.cov.flag.open"))
|
|
|
|
|
covCmd.Flags().Float64Var(&covThreshold, "threshold", 0, i18n.T("cmd.go.cov.flag.threshold"))
|
2026-01-30 00:47:54 +00:00
|
|
|
|
|
|
|
|
parent.AddCommand(covCmd)
|
2026-01-30 00:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func findTestPackages(root string) ([]string, error) {
|
|
|
|
|
pkgMap := make(map[string]bool)
|
|
|
|
|
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if !info.IsDir() && strings.HasSuffix(info.Name(), "_test.go") {
|
|
|
|
|
dir := filepath.Dir(path)
|
|
|
|
|
if !strings.HasPrefix(dir, ".") {
|
|
|
|
|
dir = "./" + dir
|
|
|
|
|
}
|
|
|
|
|
pkgMap[dir] = true
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pkgs []string
|
|
|
|
|
for pkg := range pkgMap {
|
|
|
|
|
pkgs = append(pkgs, pkg)
|
|
|
|
|
}
|
|
|
|
|
return pkgs, nil
|
|
|
|
|
}
|