Skip to content

Commit

Permalink
use io.ReadAll
Browse files Browse the repository at this point in the history
before this the stdin option wouldn't be able to read
stding that contained newlines
  • Loading branch information
mauricedesaxe committed Jul 19, 2024
1 parent 514f37e commit 0b6bb36
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"bufio"
"errors"
"flag"
"fmt"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0b6bb36

Please sign in to comment.