diff --git a/pkg/cmd/version/version.go b/pkg/cmd/version/version.go index a4c60d7..ecc627e 100644 --- a/pkg/cmd/version/version.go +++ b/pkg/cmd/version/version.go @@ -11,6 +11,11 @@ var VersionCmd = &cobra.Command{ Short: "Displays the version of diffr", Long: ``, Run: func(cmd *cobra.Command, args []string) { - cmd.Printf("Diffr Version: %s", os.Getenv("VERSION")) + version := os.Getenv("VERSION") + if version == "" { + version = "develop" + } + + cmd.Printf("Diffr Version: %s", version) }, } diff --git a/pkg/diffr/diff.go b/pkg/diffr/diff.go index 634583c..3c98bce 100644 --- a/pkg/diffr/diff.go +++ b/pkg/diffr/diff.go @@ -65,6 +65,7 @@ func compareFiles(file1, file2 string) (string, error) { func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan chan<- error, wg *sync.WaitGroup) { defer wg.Done() + var comparisonsCount int filepath.Walk(dir1, func(path1 string, info os.FileInfo, err error) error { if err != nil { errorChan <- fmt.Errorf("error accessing %s: %s", path1, err) @@ -91,6 +92,7 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha } if diff != "" { + comparisonsCount++ diffChan <- fmt.Sprintf("Differences in file: %s\n%s", relPath, diff) } } else if os.IsNotExist(err) { @@ -108,6 +110,7 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha } if diff != "" { + comparisonsCount++ diffChan <- fmt.Sprintf("Differences in file: %s (present in %s but not in %s)\n%s", relPath, dir1, dir2, diff) } } else { @@ -116,4 +119,6 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha return nil }) + + fmt.Printf("Total file comparisons: %d\n", comparisonsCount) // Print the count at the end } diff --git a/pkg/diffr/handler.go b/pkg/diffr/handler.go index 04bee4d..1e84b12 100644 --- a/pkg/diffr/handler.go +++ b/pkg/diffr/handler.go @@ -10,6 +10,7 @@ import ( "runtime" "sync" "syscall" + "time" "github.com/spf13/cobra" ) @@ -92,11 +93,14 @@ func handler(w http.ResponseWriter, r *http.Request) { finalStr = "" diffChan = make(chan string) errorChan = make(chan error) + start = time.Now() + elapsed time.Duration ) go func() { for diff := range diffChan { finalStr += diff + elapsed = time.Since(start) } }() @@ -113,6 +117,8 @@ func handler(w http.ResponseWriter, r *http.Request) { close(diffChan) close(errorChan) + fmt.Printf("Time taken to analyze all files: %s\n", elapsed) + tmpl, err := template.ParseFiles("static/templates/template.html") if err != nil { fmt.Printf("error: %v", err)