Make CLI functions return error instead of fatal out (#1379)

Before this PR, CLI functions fatal out when encountering error
instead of returning it. Such behavior makes it hard to reuse 
the functions nor writing unit tests. This PR aims to make functions 
return errors instead of error out.
This commit is contained in:
Ta-Ching Chen
2019-11-05 16:50:13 +08:00
committed by GitHub
parent b0d27ee5d2
commit 93d4b88d84
72 changed files with 894 additions and 632 deletions
@@ -17,7 +17,6 @@ limitations under the License.
package urfavecli
import (
"log"
"time"
"github.com/urfave/cli"
@@ -39,13 +38,7 @@ func Parse(c *cli.Context) fCli.Input {
func Wrapper(action cmd.CommandAction) func(*cli.Context) error {
return func(c *cli.Context) error {
e := action(Cli{c: c})
// Urfave cli doesn't exit with error code even error is not nil.
// We have to check whether error is empty and print error log here.
if e != nil {
log.Fatalf("%v", e)
}
return e
return action(Cli{c: c})
}
}