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:
@@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user