fix obscure bugs

This commit is contained in:
2026-05-16 03:56:06 +08:00
parent 3012507fcc
commit 5e5727f021
2 changed files with 56 additions and 44 deletions
+3 -40
View File
@@ -10,7 +10,6 @@ import (
"cliprepo/internal/config"
"cliprepo/internal/resolver"
"cliprepo/internal/tree"
"cliprepo/internal/utils"
"github.com/atotto/clipboard"
"github.com/spf13/cobra"
@@ -49,49 +48,15 @@ var runCmd = &cobra.Command{
}
patterns := []string(raw)
var files []string
for _, pattern := range patterns {
// =========================
// FULL REPO SCAN
// =========================
if pattern == "*" {
all, err := r.WalkAll()
if err != nil {
return err
}
files = append(files, all...)
continue
}
// =========================
// recursive glob support
// =========================
if strings.Contains(pattern, "**") {
matches, err := utils.ExpandGlob([]string{pattern})
if err != nil {
return err
}
for _, m := range matches {
r.AddFile(m, &files)
}
continue
}
// =========================
// normal glob
// =========================
matches, err := utils.ExpandGlob([]string{pattern})
// 统一交给 resolver 处理,无论是 "*", "cmd/*" 还是 "**/*.go"
matches, err := r.ResolvePattern(pattern)
if err != nil {
return err
}
for _, m := range matches {
r.AddFile(m, &files)
}
files = append(files, matches...)
}
// 3. dedup + stable order
@@ -106,13 +71,11 @@ var runCmd = &cobra.Command{
// 5. render
for _, file := range files {
content, err := os.ReadFile(file)
if err != nil {
continue
}
// 先初始化 filePath 变量,避免作用域及同名包冲突
filePath := file
if cfg.Config.PathMode == "absolute" {
abs, _ := filepath.Abs(file)