From 598457c0b6e8d52659d1915765875c8eed0b15f8 Mon Sep 17 00:00:00 2001 From: lazaralex98 Date: Fri, 19 Jul 2024 16:26:26 +0300 Subject: [PATCH] fix: use io.ReadAll before this the stdin option wouldn't be able to read stding that contained newlines --- main.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 48d942a..bd48df2 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,10 @@ package main import ( - "bufio" "errors" "flag" "fmt" + "io" "log" "os" "path/filepath" @@ -51,12 +51,11 @@ func templCSSSort(flags Flags) { // if stdin flag is set, read from stdin and write to stdout if flags.stdin { - scanner := bufio.NewScanner(os.Stdin) - buf := make([]byte, 0, 64*1024) // 64KB buffer - scanner.Buffer(buf, 64*1024) - scanner.Scan() - content := scanner.Text() - newContent, err := processContent(content) + content, err := io.ReadAll(os.Stdin) + if err != nil { + log.Fatal(err) + } + newContent, err := processContent(string(content)) if err != nil { log.Fatal(err) } @@ -181,7 +180,7 @@ func processContent(content string) (string, error) { } // replace class list in file - content = strings.Replace(content, match[0], "class=\""+newClassList+"\"", -1) + content = strings.Replace(content, match[0], `class="`+newClassList+`"`, -1) if content == "" { continue }