Replace flag text with const (#1391)

This commit is contained in:
Ta-Ching Chen
2019-11-09 22:13:35 +08:00
committed by GitHub
parent 6f5f6900b6
commit d3d8ff6c1b
73 changed files with 867 additions and 926 deletions
+7 -5
View File
@@ -30,8 +30,10 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Create),
}
wrapper.SetFlags(createCmd, flag.FlagSet{
Required: []flag.Flag{flag.KwFnNameFlag, flag.KwObjTypeFlag},
Optional: []flag.Flag{flag.NamespaceFunctionFlag, flag.KwLabelsFlag, flag.SpecSaveFlag},
Required: []flag.Flag{flag.KwFnName},
Optional: []flag.Flag{flag.KwName, flag.KwObjType, flag.NamespaceFunction, flag.SpecSave},
// TODO: add label selector flag
// flag.KwLabelsFlag
})
deleteCmd := &cobra.Command{
@@ -41,8 +43,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.KwFnNameFlag},
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Required: []flag.Flag{flag.KwFnName},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
listCmd := &cobra.Command{
@@ -52,7 +54,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{
+20 -38
View File
@@ -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"
)
@@ -35,55 +37,35 @@ type CreateSubCommand struct {
watcher *fv1.KubernetesWatchTrigger
}
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 {
fnName := flags.String("function")
if len(fnName) == 0 {
return errors.New("Need a function name to create a watch, use --function")
func (opts *CreateSubCommand) complete(input cli.Input) error {
watchName := input.String(flagkey.KwName)
if len(watchName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.MqtName))
watchName = uuid.NewV4().String()
}
fnNamespace := flags.String("fnNamespace")
namespace := flags.String("ns")
if len(namespace) == 0 {
fmt.Println("Watch 'default' namespace. Use --ns <namespace> to override.")
namespace = "default"
}
objType := flags.String("type")
if len(objType) == 0 {
fmt.Println("Object type unspecified, will watch pods. Use --type <type> to override.")
objType = "pod"
}
labels := flags.String("labels")
// empty 'labels' selects everything
if len(labels) == 0 {
fmt.Printf("Watching all objects of type '%v', use --labels to refine selection.\n", objType)
} else {
// TODO
fmt.Printf("Label selector not implemented, watching all objects")
}
// automatically name watches
watchName := uuid.NewV4().String()
fnName := input.String(flagkey.KwFnName)
fnNamespace := input.String(flagkey.NamespaceFunction)
namespace := input.String(flagkey.KwNamespace)
objType := input.String(flagkey.KwObjType)
opts.watcher = &fv1.KubernetesWatchTrigger{
Metadata: metav1.ObjectMeta{
@@ -104,9 +86,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("kubewatch-%v.yaml", opts.watcher.Metadata.Name)
err := spec.SpecSave(*opts.watcher, specFile)
if err != nil {
@@ -120,6 +102,6 @@ func (opts *CreateSubCommand) run(flags cli.Input) error {
return errors.Wrap(err, "error creating kubewatch")
}
fmt.Printf("kubewatch '%v' created\n", opts.watcher.Metadata.Name)
fmt.Printf("trigger '%v' created\n", opts.watcher.Metadata.Name)
return nil
}
+12 -14
View File
@@ -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"
)
@@ -33,35 +34,32 @@ type DeleteSubCommand struct {
namespace string
}
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 {
opts.name = flags.String("name")
if len(opts.name) == 0 {
return errors.New("need name of watch to delete, use --name")
}
opts.namespace = flags.String("triggerns")
func (opts *DeleteSubCommand) complete(input cli.Input) error {
opts.name = input.String(flagkey.KwName)
opts.namespace = input.String(flagkey.NamespaceTrigger)
return nil
}
func (opts *DeleteSubCommand) run(flags cli.Input) error {
func (opts *DeleteSubCommand) run(input cli.Input) error {
err := opts.client.WatchDelete(&metav1.ObjectMeta{
Name: opts.name,
Namespace: opts.namespace,
@@ -70,6 +68,6 @@ func (opts *DeleteSubCommand) run(flags cli.Input) error {
return errors.Wrap(err, "error deleting kubewatch")
}
fmt.Printf("watch '%v' deleted\n", opts.name)
fmt.Printf("trigger '%v' deleted\n", opts.name)
return nil
}
+10 -9
View File
@@ -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,31 +34,31 @@ 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 {
func (opts *ListSubCommand) run(input cli.Input) error {
ws, err := opts.client.WatchList(opts.namespace)
if err != nil {
return errors.Wrap(err, "error listing kubewatches")