Skip to content

Commit

Permalink
Use scanner vs reader for watch
Browse files Browse the repository at this point in the history
  • Loading branch information
vbo committed Feb 3, 2025
1 parent d7d915f commit 5e6d4fe
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions golings/cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"os"
"path/filepath"
"strings"

"github.com/fatih/color"
"github.com/fsnotify/fsnotify"
Expand All @@ -20,7 +19,7 @@ func WatchCmd(infoFile string) *cobra.Command {
Short: "Verify exercises when files are edited",
RunE: func(cmd *cobra.Command, args []string) error {
RunNextExercise(infoFile)
reader := bufio.NewReader(os.Stdin)
scanner := bufio.NewScanner(os.Stdin)
update := make(chan string)

go WatchEvents(update)
Expand All @@ -32,11 +31,11 @@ func WatchCmd(infoFile string) *cobra.Command {
}
}()

cmdString, err := reader.ReadString('\n')
if err != nil {
fmt.Fprintln(os.Stderr, err)
scanner.Scan()
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "reading standard input:", err)
}
cmdStr := strings.TrimSuffix(cmdString, "\n")
cmdStr := scanner.Text()

switch cmdStr {
case "list":
Expand Down

0 comments on commit 5e6d4fe

Please sign in to comment.