bpmodify: respect exitCode

main() method calls os.Exit(exitCode) upon return, respecting any
exitCode set by the report() method.

Test: bpmodify -w; echo "$?"
Test: bpmodify Android.bp; echo "$?"
Test: # echo command should output "2"
Change-Id: Iaf056301eaba3f249b256ecf0f0d87f8a4df1c58
This commit is contained in:
Yo Chiang 2020-03-05 11:12:42 +08:00
parent 03d3ee51f6
commit e5a91f55e4

View file

@ -223,12 +223,13 @@ func walkDir(path string) {
} }
func main() { func main() {
defer func() { os.Exit(exitCode) }()
flag.Parse() flag.Parse()
if flag.NArg() == 0 { if flag.NArg() == 0 {
if *write { if *write {
fmt.Fprintln(os.Stderr, "error: cannot use -w with standard input") report(fmt.Errorf("error: cannot use -w with standard input"))
exitCode = 2
return return
} }
if err := processFile("<standard input>", os.Stdin, os.Stdout); err != nil { if err := processFile("<standard input>", os.Stdin, os.Stdout); err != nil {