Skip to content

Commit

Permalink
Merge pull request #14 from digitalsanctum/master
Browse files Browse the repository at this point in the history
Add trim to prevent dupes from whitespace
  • Loading branch information
tomnomnom authored Mar 15, 2022
2 parents 191c684 + 44c0037 commit 9aba067
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"fmt"
"io"
"os"
"strings"
)

func main() {
var quietMode bool
var dryRun bool
var trim bool
flag.BoolVar(&quietMode, "q", false, "quiet mode (no output at all)")
flag.BoolVar(&dryRun, "d", false, "don't append anything to the file, just print the new lines to stdout")
flag.BoolVar(&trim, "t", false, "trim leading and trailing whitespace before comparison")
flag.Parse()

fn := flag.Arg(0)
Expand All @@ -28,7 +31,11 @@ func main() {
sc := bufio.NewScanner(r)

for sc.Scan() {
lines[sc.Text()] = true
if trim {
lines[strings.TrimSpace(sc.Text())] = true
} else {
lines[sc.Text()] = true
}
}
r.Close()
}
Expand All @@ -49,6 +56,9 @@ func main() {

for sc.Scan() {
line := sc.Text()
if trim {
line = strings.TrimSpace(line)
}
if lines[line] {
continue
}
Expand Down

0 comments on commit 9aba067

Please sign in to comment.