summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2024-10-15 10:10:36 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2024-10-15 10:10:36 +0200
commitcdeff3519111f923d68cf0b501d80e00782eaa7c (patch)
treee35f2a6d0ba181b46a6bd19590c965c10927a56e
parente0d7a9625714a6194bb8a21729efae72dea93729 (diff)
refactor(kdev): Simplify mainv0.5.3
-rw-r--r--cmd/kdev/main.go29
1 files changed, 16 insertions, 13 deletions
diff --git a/cmd/kdev/main.go b/cmd/kdev/main.go
index 94d4d72..f639716 100644
--- a/cmd/kdev/main.go
+++ b/cmd/kdev/main.go
@@ -72,8 +72,23 @@ func main() {
kcore.Expect(err, "Error getting HEAD")
head, err := repo.CommitObject(ref.Hash())
kcore.Expect(err, "Error getting commit object")
+ kcore.Expect(walkRepo(keywords, head, records), "Error walking directory")
+
+ records = lo.Filter(records, func(record Record, index int) bool { return record.date.After(after) })
+ if *sortBy == "random" {
+ records = lo.Shuffle(records)
+ } else {
+ slices.SortFunc(records, func(a, b Record) int { return -int(a.date.Sub(b.date).Nanoseconds()) })
+ }
+ fmt.Println("")
+ for _, record := range records[:min(*maxRecords, len(records))] {
+ fmt.Printf("%s\t %s:%d\n", record.date.Format("2006-01-02"), record.path, record.line)
+ }
+}
+
+func walkRepo(keywords []string, head *object.Commit, records []Record) error {
progress := progressbar.Default(-1, "Scanning")
- err = filepath.WalkDir(*repoPath, func(path string, d fs.DirEntry, err error) error {
+ return filepath.WalkDir(*repoPath, func(path string, d fs.DirEntry, err error) error {
relativePath := strings.TrimPrefix(path, *repoPath)
progress.Describe(relativePath)
if err != nil {
@@ -95,18 +110,6 @@ func main() {
}
return nil
})
- kcore.Expect(err, "Error walking directory")
-
- records = lo.Filter(records, func(record Record, index int) bool { return record.date.After(after) })
- if *sortBy == "random" {
- records = lo.Shuffle(records)
- } else {
- slices.SortFunc(records, func(a, b Record) int { return -int(a.date.Sub(b.date).Nanoseconds()) })
- }
- fmt.Println("")
- for _, record := range records[:min(*maxRecords, len(records))] {
- fmt.Printf("%s\t %s:%d\n", record.date.Format("2006-01-02"), record.path, record.line)
- }
}
type MatchingLine struct {