Replace flag text with const (#1391)
This commit is contained in:
@@ -30,10 +30,10 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.MqtFnNameFlag, flag.MqtTopicFlag},
|
||||
Optional: []flag.Flag{flag.MqtNameFlag, flag.NamespaceFunctionFlag, flag.MqtMQTypeFlag,
|
||||
flag.MqtRespTopicFlag, flag.MqtErrorTopicFlag, flag.MqtMaxRetriesFlag, flag.MqtMsgContentTypeFlag,
|
||||
flag.SpecSaveFlag},
|
||||
Required: []flag.Flag{flag.MqtFnName, flag.MqtTopic},
|
||||
Optional: []flag.Flag{flag.MqtName, flag.NamespaceFunction, flag.MqtMQType,
|
||||
flag.MqtRespTopic, flag.MqtErrorTopic, flag.MqtMaxRetries, flag.MqtMsgContentType,
|
||||
flag.SpecSave},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
@@ -43,9 +43,9 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(updateCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.MqtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag, flag.MqtTopicFlag, flag.MqtRespTopicFlag,
|
||||
flag.MqtErrorTopicFlag, flag.MqtMaxRetriesFlag, flag.MqtFnNameFlag, flag.MqtMsgContentTypeFlag},
|
||||
Required: []flag.Flag{flag.MqtName},
|
||||
Optional: []flag.Flag{flag.NamespaceTrigger, flag.MqtTopic, flag.MqtRespTopic,
|
||||
flag.MqtErrorTopic, flag.MqtMaxRetries, flag.MqtFnName, flag.MqtMsgContentType},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
@@ -55,8 +55,8 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.MqtNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
|
||||
Required: []flag.Flag{flag.MqtName},
|
||||
Optional: []flag.Flag{flag.NamespaceTrigger},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
@@ -66,7 +66,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceTrigger},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
|
||||
@@ -27,6 +27,8 @@ import (
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"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/console"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
)
|
||||
@@ -36,38 +38,36 @@ type CreateSubCommand struct {
|
||||
trigger *fv1.MessageQueueTrigger
|
||||
}
|
||||
|
||||
func Create(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Create(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := CreateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *CreateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
mqtName := flags.String("name")
|
||||
func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
mqtName := input.String(flagkey.MqtName)
|
||||
if len(mqtName) == 0 {
|
||||
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.MqtName))
|
||||
mqtName = uuid.NewV4().String()
|
||||
}
|
||||
fnName := flags.String("function")
|
||||
if len(fnName) == 0 {
|
||||
return errors.New("Need a function name to create a trigger, use --function")
|
||||
}
|
||||
fnNamespace := flags.String("fnNamespace")
|
||||
fnName := input.String(flagkey.MqtFnName)
|
||||
fnNamespace := input.String(flagkey.NamespaceFunction)
|
||||
|
||||
var mqType fv1.MessageQueueType
|
||||
switch flags.String("mqtype") {
|
||||
switch input.String(flagkey.MqtMQType) {
|
||||
case "":
|
||||
mqType = types.MessageQueueTypeNats
|
||||
case types.MessageQueueTypeNats:
|
||||
@@ -80,28 +80,26 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
return errors.New("Unknown message queue type, currently only \"nats-streaming, azure-storage-queue, kafka \" is supported")
|
||||
}
|
||||
|
||||
// TODO: check topic availability
|
||||
topic := flags.String("topic")
|
||||
topic := input.String(flagkey.MqtTopic)
|
||||
if len(topic) == 0 {
|
||||
return errors.New("Topic cannot be empty")
|
||||
return errors.New("topic cannot be empty")
|
||||
}
|
||||
respTopic := flags.String("resptopic")
|
||||
|
||||
respTopic := input.String(flagkey.MqtRespTopic)
|
||||
if topic == respTopic {
|
||||
// TODO maybe this should just be a warning, perhaps
|
||||
// allow it behind a --force flag
|
||||
return errors.New("Listen topic should not equal to response topic")
|
||||
return errors.New("listen topic should not equal to response topic")
|
||||
}
|
||||
|
||||
errorTopic := flags.String("errortopic")
|
||||
|
||||
maxRetries := flags.Int("maxretries")
|
||||
errorTopic := input.String(flagkey.MqtErrorTopic)
|
||||
maxRetries := input.Int(flagkey.MqtMaxRetries)
|
||||
|
||||
if maxRetries < 0 {
|
||||
return errors.New("Maximum number of retries must be a natural number, default is 0")
|
||||
return errors.New("Maximum number of retries must be greater than or equal to 0")
|
||||
}
|
||||
|
||||
contentType := flags.String("contenttype")
|
||||
contentType := input.String(flagkey.MqtMsgContentType)
|
||||
if len(contentType) == 0 {
|
||||
contentType = "application/json"
|
||||
}
|
||||
@@ -133,9 +131,9 @@ func (opts *CreateSubCommand) complete(flags cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) run(flags cli.Input) error {
|
||||
func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
// if we're writing a spec, don't call the API
|
||||
if flags.Bool("spec") {
|
||||
if input.Bool(flagkey.SpecSave) {
|
||||
specFile := fmt.Sprintf("mqtrigger-%v.yaml", opts.trigger.Metadata.Name)
|
||||
err := spec.SpecSave(*opts.trigger, specFile)
|
||||
if err != nil {
|
||||
@@ -149,14 +147,14 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
|
||||
return errors.Wrap(err, "create message queue trigger")
|
||||
}
|
||||
|
||||
fmt.Printf("message queue trigger '%s' created\n", opts.trigger.Metadata.Name)
|
||||
fmt.Printf("trigger '%s' created\n", opts.trigger.Metadata.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkMQTopicAvailability(mqType fv1.MessageQueueType, topics ...string) error {
|
||||
for _, t := range topics {
|
||||
if len(t) > 0 && !fv1.IsTopicValid(mqType, t) {
|
||||
return errors.Errorf("Invalid topic for %s: %s", mqType, t)
|
||||
return errors.Errorf("invalid topic for %s: %s", mqType, t)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -32,40 +33,39 @@ type DeleteSubCommand struct {
|
||||
metadata *metav1.ObjectMeta
|
||||
}
|
||||
|
||||
func Delete(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Delete(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := DeleteSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) complete(flags cli.Input) error {
|
||||
m, err := util.GetMetadata("name", "triggerns", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
func (opts *DeleteSubCommand) complete(input cli.Input) error {
|
||||
opts.metadata = &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.MqtName),
|
||||
Namespace: input.String(flagkey.NamespaceTrigger),
|
||||
}
|
||||
opts.metadata = m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) run(flags cli.Input) error {
|
||||
err := opts.client.WatchDelete(opts.metadata)
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) error {
|
||||
err := opts.client.MessageQueueTriggerDelete(opts.metadata)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting message queue trigger")
|
||||
}
|
||||
|
||||
fmt.Printf("message queue trigger '%v' deleted\n", opts.metadata.Name)
|
||||
fmt.Printf("trigger '%v' deleted\n", opts.metadata.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -33,32 +34,32 @@ type ListSubCommand struct {
|
||||
namespace string
|
||||
}
|
||||
|
||||
func List(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func List(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ListSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) complete(flags cli.Input) error {
|
||||
opts.namespace = flags.String("triggerns")
|
||||
func (opts *ListSubCommand) complete(input cli.Input) error {
|
||||
opts.namespace = input.String(flagkey.NamespaceTrigger)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) run(flags cli.Input) error {
|
||||
mqts, err := opts.client.MessageQueueTriggerList(flags.String("mqtype"), opts.namespace)
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
mqts, err := opts.client.MessageQueueTriggerList(input.String(flagkey.MqtMQType), opts.namespace)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing message queue triggers")
|
||||
}
|
||||
|
||||
@@ -20,10 +20,12 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
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"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -32,42 +34,40 @@ type UpdateSubCommand struct {
|
||||
trigger *fv1.MessageQueueTrigger
|
||||
}
|
||||
|
||||
func Update(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Update(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := UpdateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
m, err := util.GetMetadata("name", "triggerns", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mqt, err := opts.client.MessageQueueTriggerGet(m)
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
mqt, err := opts.client.MessageQueueTriggerGet(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.MqtName),
|
||||
Namespace: input.String(flagkey.NamespaceTrigger),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting message queue trigger")
|
||||
}
|
||||
|
||||
topic := flags.String("topic")
|
||||
respTopic := flags.String("resptopic")
|
||||
errorTopic := flags.String("errortopic")
|
||||
maxRetries := flags.Int("maxretries")
|
||||
fnName := flags.String("function")
|
||||
contentType := flags.String("contenttype")
|
||||
topic := input.String(flagkey.MqtTopic)
|
||||
respTopic := input.String(flagkey.MqtRespTopic)
|
||||
errorTopic := input.String(flagkey.MqtErrorTopic)
|
||||
maxRetries := input.Int(flagkey.MqtMaxRetries)
|
||||
fnName := input.String(flagkey.MqtFnName)
|
||||
contentType := input.String(flagkey.MqtMsgContentType)
|
||||
|
||||
// TODO : Find out if we can make a call to checkIfFunctionExists, in the same ns more importantly.
|
||||
|
||||
@@ -103,14 +103,14 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
|
||||
}
|
||||
|
||||
if !updated {
|
||||
return errors.New("Nothing to update. Use --topic, --resptopic, --errortopic, --maxretries or --function.")
|
||||
return errors.New("Nothing changed, see 'help' for more details")
|
||||
}
|
||||
opts.trigger = mqt
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) run(flags cli.Input) error {
|
||||
func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
_, err := opts.client.MessageQueueTriggerUpdate(opts.trigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating message queue trigger")
|
||||
|
||||
Reference in New Issue
Block a user