diff --git a/cmd/doctor/cmd_doctor.go b/cmd/doctor/cmd_doctor.go index 4e8a7040..0b73e2a4 100644 --- a/cmd/doctor/cmd_doctor.go +++ b/cmd/doctor/cmd_doctor.go @@ -2,6 +2,7 @@ package doctor import ( + "errors" "fmt" "forge.lthn.ai/core/cli/pkg/cli" @@ -95,10 +96,10 @@ func runDoctor(verbose bool) error { // Summary fmt.Println() 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")) 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")) diff --git a/cmd/doctor/cmd_environment.go b/cmd/doctor/cmd_environment.go index 3663a7cd..f71c4533 100644 --- a/cmd/doctor/cmd_environment.go +++ b/cmd/doctor/cmd_environment.go @@ -46,7 +46,7 @@ func checkGitHubCLI() bool { func checkWorkspace() { registryPath, err := repos.FindRegistry(io.Local) 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) if err == nil { @@ -71,7 +71,7 @@ func checkWorkspace() { 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 { fmt.Printf(" %s %s\n", dimStyle.Render("○"), i18n.T("cmd.doctor.no_repos_yaml")) diff --git a/cmd/module/cmd_install.go b/cmd/module/cmd_install.go index 0cade6b8..c35d513b 100644 --- a/cmd/module/cmd_install.go +++ b/cmd/module/cmd_install.go @@ -2,7 +2,7 @@ package module import ( "context" - "fmt" + "errors" "forge.lthn.ai/core/cli/pkg/cli" "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."), func(cmd *cli.Command, args []string) error { if installRepo == "" { - return fmt.Errorf("--repo flag is required") + return errors.New("--repo flag is required") } return runInstall(args[0], installRepo, installSignKey) }, diff --git a/cmd/module/cmd_update.go b/cmd/module/cmd_update.go index 4b5fcf3c..c3583af4 100644 --- a/cmd/module/cmd_update.go +++ b/cmd/module/cmd_update.go @@ -2,6 +2,7 @@ package module import ( "context" + "errors" "fmt" "forge.lthn.ai/core/cli/pkg/cli" @@ -20,7 +21,7 @@ func addUpdateCommand(parent *cli.Command) { return runUpdateAll() } 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]) }, diff --git a/cmd/pkgcmd/cmd_search.go b/cmd/pkgcmd/cmd_search.go index 7da952b0..e0e087a5 100644 --- a/cmd/pkgcmd/cmd_search.go +++ b/cmd/pkgcmd/cmd_search.go @@ -1,13 +1,14 @@ package pkgcmd import ( + "cmp" "encoding/json" "errors" "fmt" "os" "os/exec" "path/filepath" - "sort" + "slices" "strings" "time" @@ -147,8 +148,8 @@ func runPkgSearch(org, pattern, repoType string, limit int, refresh bool) error return nil } - sort.Slice(filtered, func(i, j int) bool { - return filtered[i].Name < filtered[j].Name + slices.SortFunc(filtered, func(a, b ghRepo) int { + return cmp.Compare(a.Name, b.Name) }) fmt.Print(i18n.T("cmd.pkg.search.found_repos", map[string]int{"Count": len(filtered)}) + "\n\n") diff --git a/cmd/plugin/cmd_update.go b/cmd/plugin/cmd_update.go index 0edcf997..60014b79 100644 --- a/cmd/plugin/cmd_update.go +++ b/cmd/plugin/cmd_update.go @@ -2,6 +2,7 @@ package plugin import ( "context" + "errors" "fmt" "forge.lthn.ai/core/cli/pkg/cli" @@ -22,7 +23,7 @@ func addUpdateCommand(parent *cli.Command) { return runUpdateAll() } 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]) }, diff --git a/pkg/cli/daemon.go b/pkg/cli/daemon.go index 961bb268..580b83a5 100644 --- a/pkg/cli/daemon.go +++ b/pkg/cli/daemon.go @@ -3,6 +3,7 @@ package cli import ( "context" + "errors" "fmt" "net" "net/http" @@ -309,7 +310,7 @@ func (d *Daemon) Start() error { defer d.mu.Unlock() if d.running { - return fmt.Errorf("daemon already running") + return errors.New("daemon already running") } // Acquire PID file @@ -339,7 +340,7 @@ func (d *Daemon) Run(ctx context.Context) error { d.mu.Lock() if !d.running { d.mu.Unlock() - return fmt.Errorf("daemon not started - call Start() first") + return errors.New("daemon not started - call Start() first") } d.mu.Unlock() diff --git a/pkg/cli/frame.go b/pkg/cli/frame.go index 74364131..ad679551 100644 --- a/pkg/cli/frame.go +++ b/pkg/cli/frame.go @@ -266,10 +266,7 @@ func (f *Frame) viewLocked() string { footerH = 1 } } - middleH := h - headerH - footerH - if middleH < 1 { - middleH = 1 - } + middleH := max(h-headerH-footerH, 1) // Render each region header := f.renderRegionLocked(RegionHeader, w, headerH) @@ -287,10 +284,7 @@ func (f *Frame) viewLocked() string { rightW = w / 4 } } - contentW := w - leftW - rightW - if contentW < 1 { - contentW = 1 - } + contentW := max(w-leftW-rightW, 1) left := f.renderRegionLocked(RegionLeft, leftW, middleH) right := f.renderRegionLocked(RegionRight, rightW, middleH) diff --git a/pkg/cli/prompt.go b/pkg/cli/prompt.go index d9eb993e..0532901f 100644 --- a/pkg/cli/prompt.go +++ b/pkg/cli/prompt.go @@ -2,6 +2,7 @@ package cli import ( "bufio" + "errors" "fmt" "os" "strconv" @@ -45,7 +46,7 @@ func Select(label string, options []string) (string, error) { n, err := strconv.Atoi(strings.TrimSpace(input)) if err != nil || n < 1 || n > len(options) { - return "", fmt.Errorf("invalid selection") + return "", errors.New("invalid selection") } return options[n-1], nil } diff --git a/pkg/cli/styles.go b/pkg/cli/styles.go index e5c40864..3813b1a8 100644 --- a/pkg/cli/styles.go +++ b/pkg/cli/styles.go @@ -288,10 +288,7 @@ func (t *Table) constrainWidths(widths []int) { } // Shrink widest columns first until we fit. - budget := t.maxWidth - overhead - if budget < cols { - budget = cols - } + budget := max(t.maxWidth-overhead, cols) for total-overhead > budget { maxIdx, maxW := 0, 0 for i, w := range widths { diff --git a/pkg/cli/utils.go b/pkg/cli/utils.go index 13d0471a..da84cb3a 100644 --- a/pkg/cli/utils.go +++ b/pkg/cli/utils.go @@ -3,6 +3,7 @@ package cli import ( "bufio" "context" + "errors" "fmt" "os" "os/exec" @@ -474,7 +475,6 @@ func parseMultiSelection(input string, maxItems int) ([]int, error) { return result, nil } - // ChooseMultiAction prompts for multiple selections using grammar composition. // // files := ChooseMultiAction("select", "files", files) @@ -495,14 +495,14 @@ func GitClone(ctx context.Context, org, repo, path string) error { } errStr := strings.TrimSpace(string(output)) if strings.Contains(errStr, "already exists") { - return fmt.Errorf("%s", errStr) + return errors.New(errStr) } } // Fall back to SSH clone cmd := exec.CommandContext(ctx, "git", "clone", fmt.Sprintf("git@github.com:%s/%s.git", org, repo), path) output, err := cmd.CombinedOutput() if err != nil { - return fmt.Errorf("%s", strings.TrimSpace(string(output))) + return errors.New(strings.TrimSpace(string(output))) } return nil }