Migrate from urfave/cli to cobra (#1385)
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package httptrigger
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create an HTTP trigger",
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.HtUrlFlag, flag.HtFnNameFlag},
|
||||
Optional: []flag.Flag{flag.HtNameFlag, flag.HtMethodFlag, flag.HtIngressRuleFlag,
|
||||
flag.HtIngressAnnotationFlag, flag.HtIngressTLSFlag, flag.HtIngressFlag,
|
||||
flag.HtFnWeightFlag, flag.HtHostFlag, flag.NamespaceFunctionFlag, flag.SpecSaveFlag},
|
||||
})
|
||||
|
||||
getCmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Aliases: []string{},
|
||||
Short: "Get HTTP trigger details",
|
||||
RunE: wrapper.Wrapper(Get),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.HtNameFlag},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
Use: "update",
|
||||
Aliases: []string{},
|
||||
Short: "Update an HTTP trigger",
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.HtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.HtFnNameFlag, flag.HtUrlFlag,
|
||||
flag.HtMethodFlag, flag.HtIngressRuleFlag, flag.HtIngressAnnotationFlag,
|
||||
flag.HtIngressTLSFlag, flag.HtIngressFlag, flag.HtFnWeightFlag, flag.HtHostFlag},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete",
|
||||
Aliases: []string{},
|
||||
Short: "Delete an HTTP trigger",
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.HtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.HtFnFilterFlag},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Aliases: []string{},
|
||||
Short: "List all HTTP triggers in a namespace if specified, else, list HTTP triggers across all namespaces",
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.HtFnFilterFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "httptrigger",
|
||||
Aliases: []string{"ht", "route"},
|
||||
Short: "Create, update and manage HTTP triggers",
|
||||
}
|
||||
|
||||
command.AddCommand(createCmd, getCmd, updateCmd, deleteCmd, listCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -104,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 {
|
||||
consolemsg.Warn(err.Error())
|
||||
console.Warn(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
host := flags.String("host")
|
||||
if flags.IsSet("host") {
|
||||
consolemsg.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
console.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
}
|
||||
|
||||
// just name triggers by uuid.
|
||||
|
||||
@@ -19,12 +19,14 @@ 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/util"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
type DeleteSubCommand struct {
|
||||
@@ -84,7 +86,7 @@ func (opts *DeleteSubCommand) run(flags cli.Input) error {
|
||||
triggersToDelete = []string{opts.triggerName}
|
||||
}
|
||||
|
||||
errs := &multierror.Error{}
|
||||
errs := utils.MultiErrorWithFormat()
|
||||
|
||||
for _, name := range triggersToDelete {
|
||||
err := opts.client.HTTPTriggerDelete(&metav1.ObjectMeta{
|
||||
|
||||
@@ -25,7 +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/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -73,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 {
|
||||
consolemsg.Warn(err.Error())
|
||||
console.Warn(err.Error())
|
||||
}
|
||||
|
||||
var functionWeightsList []int
|
||||
@@ -96,7 +96,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
if flags.IsSet("host") {
|
||||
ht.Spec.Host = flags.String("host")
|
||||
consolemsg.Warn(fmt.Sprintf("--host is now marked as deprecated, see 'help' for details"))
|
||||
console.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