From 011752978172a13a4f68560fa7a5c387b0eaa1e7 Mon Sep 17 00:00:00 2001 From: Ali Abbas Date: Sat, 6 Dec 2014 12:50:38 +0100 Subject: [PATCH] remove control flow on errExit by switching from bool to int --- command/watch.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/command/watch.go b/command/watch.go index 0ad514b92..d5caf325a 100644 --- a/command/watch.go +++ b/command/watch.go @@ -144,14 +144,18 @@ func (c *WatchCommand) Run(args []string) int { } // Setup handler - errExit := false + + // errExit: + // 0: false + // 1: true + errExit := 0 if script == "" { wp.Handler = func(idx uint64, data interface{}) { defer wp.Stop() buf, err := json.MarshalIndent(data, "", " ") if err != nil { c.Ui.Error(fmt.Sprintf("Error encoding output: %s", err)) - errExit = true + errExit = 1 } c.Ui.Output(string(buf)) } @@ -186,7 +190,7 @@ func (c *WatchCommand) Run(args []string) int { return ERR: wp.Stop() - errExit = true + errExit = 1 } } @@ -203,12 +207,7 @@ func (c *WatchCommand) Run(args []string) int { return 1 } - // Handle an error exit - if errExit { - return 1 - } else { - return 0 - } + return errExit } func (c *WatchCommand) Synopsis() string {