Skip to content

Commit b5e5ee2

Browse files
committed
adding some logs
Signed-off-by: Raj Babu Das <mail.rajdas@gmail.com>
1 parent 40d5e82 commit b5e5ee2

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

pkg/cmd/version/version.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ var VersionCmd = &cobra.Command{
1111
Short: "Displays the version of diffr",
1212
Long: ``,
1313
Run: func(cmd *cobra.Command, args []string) {
14-
cmd.Printf("Diffr Version: %s", os.Getenv("VERSION"))
14+
version := os.Getenv("VERSION")
15+
if version == "" {
16+
version = "develop"
17+
}
18+
19+
cmd.Printf("Diffr Version: %s", version)
1520
},
1621
}

pkg/diffr/diff.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func compareFiles(file1, file2 string) (string, error) {
6565
func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan chan<- error, wg *sync.WaitGroup) {
6666
defer wg.Done()
6767

68+
var comparisonsCount int
6869
filepath.Walk(dir1, func(path1 string, info os.FileInfo, err error) error {
6970
if err != nil {
7071
errorChan <- fmt.Errorf("error accessing %s: %s", path1, err)
@@ -91,6 +92,7 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha
9192
}
9293

9394
if diff != "" {
95+
comparisonsCount++
9496
diffChan <- fmt.Sprintf("Differences in file: %s\n%s", relPath, diff)
9597
}
9698
} else if os.IsNotExist(err) {
@@ -108,6 +110,7 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha
108110
}
109111

110112
if diff != "" {
113+
comparisonsCount++
111114
diffChan <- fmt.Sprintf("Differences in file: %s (present in %s but not in %s)\n%s", relPath, dir1, dir2, diff)
112115
}
113116
} else {
@@ -116,4 +119,6 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha
116119

117120
return nil
118121
})
122+
123+
fmt.Printf("Total file comparisons: %d\n", comparisonsCount) // Print the count at the end
119124
}

pkg/diffr/handler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"runtime"
1111
"sync"
1212
"syscall"
13+
"time"
1314

1415
"github.com/spf13/cobra"
1516
)
@@ -92,11 +93,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
9293
finalStr = ""
9394
diffChan = make(chan string)
9495
errorChan = make(chan error)
96+
start = time.Now()
97+
elapsed time.Duration
9598
)
9699

97100
go func() {
98101
for diff := range diffChan {
99102
finalStr += diff
103+
elapsed = time.Since(start)
100104
}
101105
}()
102106

@@ -113,6 +117,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
113117
close(diffChan)
114118
close(errorChan)
115119

120+
fmt.Printf("Time taken to analyze all files: %s\n", elapsed)
121+
116122
tmpl, err := template.ParseFiles("static/templates/template.html")
117123
if err != nil {
118124
fmt.Printf("error: %v", err)

0 commit comments

Comments
 (0)