Merge pull request 'chore: Go 1.26 modernization' (#7) from chore/go-1.26-modernization into main
Some checks are pending
Deploy / build (push) Waiting to run
Security Scan / security (push) Waiting to run

This commit is contained in:
Charon 2026-02-24 18:01:45 +00:00
commit 4dfbddf11f
11 changed files with 26 additions and 29 deletions

View file

@ -2,6 +2,7 @@
package doctor package doctor
import ( import (
"errors"
"fmt" "fmt"
"forge.lthn.ai/core/cli/pkg/cli" "forge.lthn.ai/core/cli/pkg/cli"
@ -95,10 +96,10 @@ func runDoctor(verbose bool) error {
// Summary // Summary
fmt.Println() fmt.Println()
if failed > 0 { if failed > 0 {
cli.Error(i18n.T("cmd.doctor.issues", map[string]interface{}{"Count": failed})) cli.Error(i18n.T("cmd.doctor.issues", map[string]any{"Count": failed}))
fmt.Printf("\n%s\n", i18n.T("cmd.doctor.install_missing")) fmt.Printf("\n%s\n", i18n.T("cmd.doctor.install_missing"))
printInstallInstructions() printInstallInstructions()
return fmt.Errorf("%s", i18n.T("cmd.doctor.issues_error", map[string]interface{}{"Count": failed})) return errors.New(i18n.T("cmd.doctor.issues_error", map[string]any{"Count": failed}))
} }
cli.Success(i18n.T("cmd.doctor.ready")) cli.Success(i18n.T("cmd.doctor.ready"))

View file

@ -46,7 +46,7 @@ func checkGitHubCLI() bool {
func checkWorkspace() { func checkWorkspace() {
registryPath, err := repos.FindRegistry(io.Local) registryPath, err := repos.FindRegistry(io.Local)
if err == nil { if err == nil {
fmt.Printf(" %s %s\n", successStyle.Render("✓"), i18n.T("cmd.doctor.repos_yaml_found", map[string]interface{}{"Path": registryPath})) fmt.Printf(" %s %s\n", successStyle.Render("✓"), i18n.T("cmd.doctor.repos_yaml_found", map[string]any{"Path": registryPath}))
reg, err := repos.LoadRegistry(io.Local, registryPath) reg, err := repos.LoadRegistry(io.Local, registryPath)
if err == nil { if err == nil {
@ -71,7 +71,7 @@ func checkWorkspace() {
cloned++ cloned++
} }
} }
fmt.Printf(" %s %s\n", successStyle.Render("✓"), i18n.T("cmd.doctor.repos_cloned", map[string]interface{}{"Cloned": cloned, "Total": len(allRepos)})) fmt.Printf(" %s %s\n", successStyle.Render("✓"), i18n.T("cmd.doctor.repos_cloned", map[string]any{"Cloned": cloned, "Total": len(allRepos)}))
} }
} else { } else {
fmt.Printf(" %s %s\n", dimStyle.Render("○"), i18n.T("cmd.doctor.no_repos_yaml")) fmt.Printf(" %s %s\n", dimStyle.Render("○"), i18n.T("cmd.doctor.no_repos_yaml"))

View file

@ -2,7 +2,7 @@ package module
import ( import (
"context" "context"
"fmt" "errors"
"forge.lthn.ai/core/cli/pkg/cli" "forge.lthn.ai/core/cli/pkg/cli"
"forge.lthn.ai/core/go/pkg/i18n" "forge.lthn.ai/core/go/pkg/i18n"
@ -21,7 +21,7 @@ func addInstallCommand(parent *cli.Command) {
i18n.T("Install a module by cloning its Git repository, verifying the manifest signature, and registering it.\n\nThe --repo flag is required and specifies the Git URL to clone from."), i18n.T("Install a module by cloning its Git repository, verifying the manifest signature, and registering it.\n\nThe --repo flag is required and specifies the Git URL to clone from."),
func(cmd *cli.Command, args []string) error { func(cmd *cli.Command, args []string) error {
if installRepo == "" { if installRepo == "" {
return fmt.Errorf("--repo flag is required") return errors.New("--repo flag is required")
} }
return runInstall(args[0], installRepo, installSignKey) return runInstall(args[0], installRepo, installSignKey)
}, },

View file

@ -2,6 +2,7 @@ package module
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"forge.lthn.ai/core/cli/pkg/cli" "forge.lthn.ai/core/cli/pkg/cli"
@ -20,7 +21,7 @@ func addUpdateCommand(parent *cli.Command) {
return runUpdateAll() return runUpdateAll()
} }
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("module code required (or use --all)") return errors.New("module code required (or use --all)")
} }
return runUpdate(args[0]) return runUpdate(args[0])
}, },

View file

@ -1,13 +1,14 @@
package pkgcmd package pkgcmd
import ( import (
"cmp"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"sort" "slices"
"strings" "strings"
"time" "time"
@ -147,8 +148,8 @@ func runPkgSearch(org, pattern, repoType string, limit int, refresh bool) error
return nil return nil
} }
sort.Slice(filtered, func(i, j int) bool { slices.SortFunc(filtered, func(a, b ghRepo) int {
return filtered[i].Name < filtered[j].Name return cmp.Compare(a.Name, b.Name)
}) })
fmt.Print(i18n.T("cmd.pkg.search.found_repos", map[string]int{"Count": len(filtered)}) + "\n\n") fmt.Print(i18n.T("cmd.pkg.search.found_repos", map[string]int{"Count": len(filtered)}) + "\n\n")

View file

@ -2,6 +2,7 @@ package plugin
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"forge.lthn.ai/core/cli/pkg/cli" "forge.lthn.ai/core/cli/pkg/cli"
@ -22,7 +23,7 @@ func addUpdateCommand(parent *cli.Command) {
return runUpdateAll() return runUpdateAll()
} }
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("plugin name required (or use --all)") return errors.New("plugin name required (or use --all)")
} }
return runUpdate(args[0]) return runUpdate(args[0])
}, },

View file

@ -3,6 +3,7 @@ package cli
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
@ -309,7 +310,7 @@ func (d *Daemon) Start() error {
defer d.mu.Unlock() defer d.mu.Unlock()
if d.running { if d.running {
return fmt.Errorf("daemon already running") return errors.New("daemon already running")
} }
// Acquire PID file // Acquire PID file
@ -339,7 +340,7 @@ func (d *Daemon) Run(ctx context.Context) error {
d.mu.Lock() d.mu.Lock()
if !d.running { if !d.running {
d.mu.Unlock() d.mu.Unlock()
return fmt.Errorf("daemon not started - call Start() first") return errors.New("daemon not started - call Start() first")
} }
d.mu.Unlock() d.mu.Unlock()

View file

@ -266,10 +266,7 @@ func (f *Frame) viewLocked() string {
footerH = 1 footerH = 1
} }
} }
middleH := h - headerH - footerH middleH := max(h-headerH-footerH, 1)
if middleH < 1 {
middleH = 1
}
// Render each region // Render each region
header := f.renderRegionLocked(RegionHeader, w, headerH) header := f.renderRegionLocked(RegionHeader, w, headerH)
@ -287,10 +284,7 @@ func (f *Frame) viewLocked() string {
rightW = w / 4 rightW = w / 4
} }
} }
contentW := w - leftW - rightW contentW := max(w-leftW-rightW, 1)
if contentW < 1 {
contentW = 1
}
left := f.renderRegionLocked(RegionLeft, leftW, middleH) left := f.renderRegionLocked(RegionLeft, leftW, middleH)
right := f.renderRegionLocked(RegionRight, rightW, middleH) right := f.renderRegionLocked(RegionRight, rightW, middleH)

View file

@ -2,6 +2,7 @@ package cli
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
@ -45,7 +46,7 @@ func Select(label string, options []string) (string, error) {
n, err := strconv.Atoi(strings.TrimSpace(input)) n, err := strconv.Atoi(strings.TrimSpace(input))
if err != nil || n < 1 || n > len(options) { if err != nil || n < 1 || n > len(options) {
return "", fmt.Errorf("invalid selection") return "", errors.New("invalid selection")
} }
return options[n-1], nil return options[n-1], nil
} }

View file

@ -288,10 +288,7 @@ func (t *Table) constrainWidths(widths []int) {
} }
// Shrink widest columns first until we fit. // Shrink widest columns first until we fit.
budget := t.maxWidth - overhead budget := max(t.maxWidth-overhead, cols)
if budget < cols {
budget = cols
}
for total-overhead > budget { for total-overhead > budget {
maxIdx, maxW := 0, 0 maxIdx, maxW := 0, 0
for i, w := range widths { for i, w := range widths {

View file

@ -3,6 +3,7 @@ package cli
import ( import (
"bufio" "bufio"
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -474,7 +475,6 @@ func parseMultiSelection(input string, maxItems int) ([]int, error) {
return result, nil return result, nil
} }
// ChooseMultiAction prompts for multiple selections using grammar composition. // ChooseMultiAction prompts for multiple selections using grammar composition.
// //
// files := ChooseMultiAction("select", "files", files) // files := ChooseMultiAction("select", "files", files)
@ -495,14 +495,14 @@ func GitClone(ctx context.Context, org, repo, path string) error {
} }
errStr := strings.TrimSpace(string(output)) errStr := strings.TrimSpace(string(output))
if strings.Contains(errStr, "already exists") { if strings.Contains(errStr, "already exists") {
return fmt.Errorf("%s", errStr) return errors.New(errStr)
} }
} }
// Fall back to SSH clone // Fall back to SSH clone
cmd := exec.CommandContext(ctx, "git", "clone", fmt.Sprintf("git@github.com:%s/%s.git", org, repo), path) cmd := exec.CommandContext(ctx, "git", "clone", fmt.Sprintf("git@github.com:%s/%s.git", org, repo), path)
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return fmt.Errorf("%s", strings.TrimSpace(string(output))) return errors.New(strings.TrimSpace(string(output)))
} }
return nil return nil
} }