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:
@@ -29,9 +29,8 @@ import (
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||
"github.com/fission/fission/pkg/fission-cli/log"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -41,8 +40,12 @@ type CreateSubCommand struct {
|
||||
}
|
||||
|
||||
func Create(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := CreateSubCommand{
|
||||
client: cmd.GetServer(flags),
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
}
|
||||
@@ -101,7 +104,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
if !flags.Bool("spec") {
|
||||
err = util.CheckFunctionExistence(opts.client, functionList, fnNamespace)
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
consolemsg.Warn(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +118,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
host := flags.String("host")
|
||||
if flags.IsSet("host") {
|
||||
log.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
consolemsg.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
}
|
||||
|
||||
// just name triggers by uuid.
|
||||
|
||||
@@ -19,13 +19,12 @@ package httptrigger
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
)
|
||||
|
||||
type DeleteSubCommand struct {
|
||||
@@ -36,8 +35,12 @@ type DeleteSubCommand struct {
|
||||
}
|
||||
|
||||
func Delete(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := DeleteSubCommand{
|
||||
client: cmd.GetServer(flags),
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type GetSubCommand struct {
|
||||
@@ -38,8 +38,12 @@ type GetSubCommand struct {
|
||||
}
|
||||
|
||||
func Get(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := GetSubCommand{
|
||||
client: cmd.GetServer(flags),
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type ListSubCommand struct {
|
||||
@@ -32,8 +32,12 @@ type ListSubCommand struct {
|
||||
}
|
||||
|
||||
func List(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ListSubCommand{
|
||||
client: cmd.GetServer(flags),
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import (
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
"github.com/fission/fission/pkg/fission-cli/log"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -36,8 +35,12 @@ type UpdateSubCommand struct {
|
||||
}
|
||||
|
||||
func Update(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := UpdateSubCommand{
|
||||
client: cmd.GetServer(flags),
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
}
|
||||
@@ -70,7 +73,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
functionList := flags.StringSlice("function")
|
||||
err := util.CheckFunctionExistence(opts.client, functionList, triggerNamespace)
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
consolemsg.Warn(err.Error())
|
||||
}
|
||||
|
||||
var functionWeightsList []int
|
||||
@@ -93,7 +96,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
if flags.IsSet("host") {
|
||||
ht.Spec.Host = flags.String("host")
|
||||
log.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
consolemsg.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
}
|
||||
|
||||
if flags.IsSet("ingressrule") || flags.IsSet("ingressannotation") || flags.IsSet("ingresstls") {
|
||||
|
||||
Reference in New Issue
Block a user