started muld

main
BraydonKains 2 years ago
parent 9edf7d613c
commit 0a9924e96c

@ -1,7 +0,0 @@
package main
import "fmt"
func main() {
fmt.Println("not ready yet")
}

@ -0,0 +1,70 @@
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"runtime"
"github.com/RageCage64/multilinediff"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
if (len(os.Args) - 1) != 2 {
return fmt.Errorf("requires exactly two arguments, got %d", len(os.Args))
}
leftPath := os.Args[1]
rightPath := os.Args[2]
leftContent, err := readContent(leftPath)
if err != nil {
return err
}
rightContent, err := readContent(rightPath)
if err != nil {
return err
}
lineSep := "\n"
if runtime.GOOS == "windows" {
lineSep = "\r\n"
}
fmt.Println(multilinediff.Diff(leftContent, rightContent, lineSep))
return nil
}
func readContent(path string) (string, error) {
if path == "-" {
return readFromStdin()
}
content, err := os.ReadFile(path)
return string(content), err
}
func readFromStdin() (string, error) {
stdin := bufio.NewReader(os.Stdin)
data := []byte{}
for {
b, err := stdin.ReadByte()
if err != nil {
if err == io.EOF {
break
} else {
return "", err
}
}
data = append(data, b)
}
return string(data), nil
}

@ -1,24 +0,0 @@
package main
import (
"fmt"
"github.com/RageCage64/multilinediff"
)
func main() {
a := `a
b
c
diff`
b := `a b
c
f
f
f
diff`
diff, count := multilinediff.Diff(a, b, "\n")
fmt.Println(count)
fmt.Println("--------")
fmt.Println(diff)
}
Loading…
Cancel
Save