diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2024-10-15 10:10:36 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2024-10-15 10:10:36 +0200 |
| commit | cdeff3519111f923d68cf0b501d80e00782eaa7c (patch) | |
| tree | e35f2a6d0ba181b46a6bd19590c965c10927a56e /cmd/kdev/main.go | |
| parent | e0d7a9625714a6194bb8a21729efae72dea93729 (diff) | |
refactor(kdev): Simplify mainv0.5.3
Diffstat (limited to 'cmd/kdev/main.go')
| -rw-r--r-- | cmd/kdev/main.go | 29 |
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 { |
