Skip to content

Commit

Permalink
Fix Watcher loop/readme issue
Browse files Browse the repository at this point in the history
  • Loading branch information
aquemaati committed May 17, 2024
1 parent 0af939c commit 1f6d3f1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo.webp](logo1.webp)
# lamoul01 (for go and javascript)
Ever get stuck in the dreaded 3-minute push cooldown at the 01 Edu piscine? Say goodbye to the wait! Our app lets you run moulinette tests right in your terminal, so you can catch errors on the fly and keep your momentum going. No more ‘coding timeouts’—just pure, uninterrupted productivity!
![logo.webp](logo1.webp)

# How to install
No cheater, it’s not going to be easy for you to go over the cooldown. First, you need to pass a few steps to prove you deserve lamoul01 to flex at the piscine.
Expand Down Expand Up @@ -30,6 +30,16 @@ go to your piscine directory and run this command :
Launch these commands and let lamoul test for you:
```lamoul01 js```
```lamoul01 go```
if the command is not found, go to yourusername/go/bin and run this command
### Issue
If command not found:<br>
``` sh
echo 'export GOPATH="$(go env GOPATH)"' >> ~/.zshrc
echo 'export PATH="${PATH}:${GOPATH}/bin"' >> ~/.zshrc
source ~/.zshrc
```
Or go to yourusername/go/bin:<br>
```sudo cp lamoul01 /usr/local/bin/```
![show](imagetest.png)
![show](imagetest.png)



58 changes: 26 additions & 32 deletions internal/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,38 @@ func Watcher(testFunc func(string, string, string), testPath string) {
}
fmt.Println("🤟\033[32mCurrent directory path:\033[0m", dir)

watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}

err = watcher.Add(dir)
if err != nil {
log.Fatal(err)
}

fmt.Println("🤓\033[34mWatching directory for changes...\033[0m")

for {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
select {
case event := <-watcher.Events:
if event.Op&fsnotify.Write == fsnotify.Write {
fmt.Printf("🤫\033[33mFile modified: %s\033[0m\n", event.Name)

err = watcher.Add(dir)
if err != nil {
log.Fatal(err)
}
// Get the file name without extension
fileName := filepath.Base(event.Name)
fileNameWithoutExt := strings.TrimSuffix(fileName, filepath.Ext(fileName))

fmt.Println("🤓\033[34mWatching directory for changes...\033[0m")

done := false
for !done {
select {
case event := <-watcher.Events:
if event.Op&fsnotify.Write == fsnotify.Write {
fmt.Printf("🤫\033[33mFile modified: %s\033[0m\n", event.Name)

// Get the file name without extension
fileName := filepath.Base(event.Name)
fileNameWithoutExt := strings.TrimSuffix(fileName, filepath.Ext(fileName))

// Execute the test function with the file name without extension
testFunc(fileNameWithoutExt, dir, testPath)
done = true
}
case err := <-watcher.Errors:
if err != nil {
log.Println("🤮\033[31mError:\033[0m", err)
}
done = true
// Execute the test function with the file name without extension
testFunc(fileNameWithoutExt, dir, testPath)

}
case err := <-watcher.Errors:
if err != nil {
log.Println("🤮\033[31mError:\033[0m", err)
}
}

watcher.Close()

// Short pause before resuming watching to avoid system overload
time.Sleep(1 * time.Second)
}
Expand Down

0 comments on commit 1f6d3f1

Please sign in to comment.