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 -7
View File
@@ -30,7 +30,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Create),
}
wrapper.SetFlags(createCmd, flag.FlagSet{
Optional: []flag.Flag{flag.TtNameFlag, flag.TtFnNameFlag, flag.NamespaceFunctionFlag, flag.TtCronFlag, flag.SpecSaveFlag},
Optional: []flag.Flag{flag.TtName, flag.TtFnName, flag.NamespaceFunction, flag.TtCron, flag.SpecSave},
})
updateCmd := &cobra.Command{
@@ -40,8 +40,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Update),
}
wrapper.SetFlags(updateCmd, flag.FlagSet{
Required: []flag.Flag{flag.TtNameFlag},
Optional: []flag.Flag{flag.TtFnNameFlag, flag.NamespaceFunctionFlag, flag.TtCronFlag},
Required: []flag.Flag{flag.TtName},
Optional: []flag.Flag{flag.TtFnName, flag.NamespaceFunction, flag.TtCron},
})
deleteCmd := &cobra.Command{
@@ -51,8 +51,8 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.TtNameFlag},
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Required: []flag.Flag{flag.TtName},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
listCmd := &cobra.Command{
@@ -62,7 +62,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceTriggerFlag},
Optional: []flag.Flag{flag.NamespaceTrigger},
})
showCmd := &cobra.Command{
@@ -72,7 +72,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Show),
}
wrapper.SetFlags(showCmd, flag.FlagSet{
Optional: []flag.Flag{flag.TtCronFlag, flag.TtRoundFlag},
Optional: []flag.Flag{flag.TtCron, flag.TtRound},
})
command := &cobra.Command{
+14 -13
View File
@@ -29,6 +29,7 @@ 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"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -37,39 +38,39 @@ type CreateSubCommand struct {
trigger *fv1.TimeTrigger
}
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 {
name := flags.String("name")
func (opts *CreateSubCommand) complete(input cli.Input) error {
name := input.String(flagkey.TtName)
if len(name) == 0 {
name = uuid.NewV4().String()
}
fnName := flags.String("function")
fnName := input.String(flagkey.TtFnName)
if len(fnName) == 0 {
return errors.New("Need a function name to create a trigger, use --function")
}
fnNamespace := flags.String("fnNamespace")
fnNamespace := input.String(flagkey.NamespaceFunction)
cronSpec := flags.String("cron")
cronSpec := input.String(flagkey.TtCron)
if len(cronSpec) == 0 {
return errors.New("Need a cron spec like '0 30 * * * *', '@every 1h30m', or '@hourly'; use --cron")
}
@@ -91,9 +92,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("timetrigger-%v.yaml", opts.trigger.Metadata.Name)
err := spec.SpecSave(*opts.trigger, specFile)
if err != nil {
+10 -8
View File
@@ -20,9 +20,11 @@ import (
"fmt"
"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"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -30,24 +32,24 @@ type DeleteSubCommand struct {
client *client.Client
}
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 {
m, err := util.GetMetadata("name", "triggerns", flags)
if err != nil {
return err
func (opts *DeleteSubCommand) do(input cli.Input) error {
m := &metav1.ObjectMeta{
Name: input.String(flagkey.TtName),
Namespace: input.String(flagkey.NamespaceTrigger),
}
err = opts.client.TimeTriggerDelete(m)
err := opts.client.TimeTriggerDelete(m)
if err != nil {
return errors.Wrap(err, "error deleting trigger")
}
+6 -5
View File
@@ -23,6 +23,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"
"github.com/pkg/errors"
)
@@ -31,19 +32,19 @@ type ListSubCommand struct {
client *client.Client
}
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 {
ttNs := flags.String("triggerns")
func (opts *ListSubCommand) do(input cli.Input) error {
ttNs := input.String(flagkey.NamespaceTrigger)
tts, err := opts.client.TimeTriggerList(ttNs)
if err != nil {
return errors.Wrap(err, "list Time triggers")
+9 -8
View File
@@ -21,6 +21,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"
)
@@ -28,24 +29,24 @@ type ShowSubCommand struct {
client *client.Client
}
func Show(flags cli.Input) error {
c, err := util.GetServer(flags)
func Show(input cli.Input) error {
c, err := util.GetServer(input)
if err != nil {
return err
}
opts := ShowSubCommand{
client: c,
}
return opts.do(flags)
return opts.do(input)
}
func (opts *ShowSubCommand) do(flags cli.Input) error {
return opts.run(flags)
func (opts *ShowSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *ShowSubCommand) run(flags cli.Input) error {
round := flags.Int("round")
cronSpec := flags.String("cron")
func (opts *ShowSubCommand) run(flaginput cli.Input) error {
round := flaginput.Int(flagkey.TtName)
cronSpec := flaginput.String(flagkey.TtCron)
if len(cronSpec) == 0 {
return errors.New("need a cron spec like '0 30 * * * *', '@every 1h30m', or '@hourly'; use --cron")
}
+17 -17
View File
@@ -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,38 +34,36 @@ type UpdateSubCommand struct {
trigger *fv1.TimeTrigger
}
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
}
tt, err := opts.client.TimeTriggerGet(m)
func (opts *UpdateSubCommand) complete(input cli.Input) error {
tt, err := opts.client.TimeTriggerGet(&metav1.ObjectMeta{
Name: input.String(flagkey.TtName),
Namespace: input.String(flagkey.NamespaceTrigger),
})
if err != nil {
return errors.Wrap(err, "error getting time trigger")
}
updated := false
newCron := flags.String("cron")
newCron := input.String("cron")
if len(newCron) != 0 {
tt.Spec.Cron = newCron
updated = true
@@ -72,7 +72,7 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
// TODO : During update, function has to be in the same ns as the trigger object
// but since we are not checking this for other triggers too, not sure if we need a check here.
fnName := flags.String("function")
fnName := input.String("function")
if len(fnName) > 0 {
tt.Spec.FunctionReference.Name = fnName
updated = true
@@ -87,13 +87,13 @@ func (opts *UpdateSubCommand) complete(flags cli.Input) error {
return nil
}
func (opts *UpdateSubCommand) run(flags cli.Input) error {
func (opts *UpdateSubCommand) run(input cli.Input) error {
_, err := opts.client.TimeTriggerUpdate(opts.trigger)
if err != nil {
return errors.Wrap(err, "error updating Time trigger")
}
fmt.Printf("Time trigger '%v' updated\n", opts.trigger.Metadata.Name)
fmt.Printf("trigger '%v' updated\n", opts.trigger.Metadata.Name)
t, err := getAPITimeInfo(opts.client)
if err != nil {