Skip to content

Commit

Permalink
Merge pull request #34 from tmcgilchrist/exit_code
Browse files Browse the repository at this point in the history
Explicitly return exit codes when differences are found.
  • Loading branch information
Joseph Burnett authored Oct 29, 2021
2 parents 0e6be33 + 00f2b0a commit 9f4fdc3
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,19 @@ func printDiff(a, b string, metadata []jd.Metadata) {
}
diff := aNode.Diff(bNode, metadata...)
if *output == "" {
fmt.Print(diff.Render())
str := diff.Render()
if str == "" {
os.Exit(0)
}
fmt.Print(str)
os.Exit(1)
} else {
ioutil.WriteFile(*output, []byte(diff.Render()), 0644)
str := diff.Render()
if str == "" {
os.Exit(0)
}
ioutil.WriteFile(*output, []byte(str), 0644)
os.Exit(1)
}
}

Expand Down Expand Up @@ -178,9 +188,17 @@ func printPatch(p, a string, metadata []jd.Metadata) {
out = bNode.Json(metadata...)
}
if *output == "" {
if out == "" {
os.Exit(0)
}
fmt.Print(out)
os.Exit(1)
} else {
if out == "" {
os.Exit(0)
}
ioutil.WriteFile(*output, []byte(out), 0644)
os.Exit(1)
}
}

Expand Down

0 comments on commit 9f4fdc3

Please sign in to comment.