Replace flag text with const (#1391)
This commit is contained in:
@@ -30,7 +30,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Create),
|
||||
}
|
||||
wrapper.SetFlags(createCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.RecorderNameFlag, flag.RecorderFnFlag, flag.RecorderTriggersFlag, flag.SpecSaveFlag},
|
||||
Optional: []flag.Flag{flag.RecorderName, flag.RecorderFn, flag.RecorderTriggers, flag.SpecSave},
|
||||
})
|
||||
|
||||
getCmd := &cobra.Command{
|
||||
@@ -39,7 +39,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Get),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderNameFlag},
|
||||
Required: []flag.Flag{flag.RecorderName},
|
||||
})
|
||||
|
||||
updateCmd := &cobra.Command{
|
||||
@@ -48,8 +48,8 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Update),
|
||||
}
|
||||
wrapper.SetFlags(getCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderNameFlag},
|
||||
Optional: []flag.Flag{flag.RecorderFnFlag, flag.RecorderTriggersFlag, flag.RecorderEnabledFlag, flag.RecorderDisabledFlag},
|
||||
Required: []flag.Flag{flag.RecorderName},
|
||||
Optional: []flag.Flag{flag.RecorderFn, flag.RecorderTriggers, flag.RecorderEnabled, flag.RecorderDisabled},
|
||||
})
|
||||
|
||||
deleteCmd := &cobra.Command{
|
||||
@@ -58,8 +58,8 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Delete),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Required: []flag.Flag{flag.RecorderNameFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceRecorderFlag},
|
||||
Required: []flag.Flag{flag.RecorderName},
|
||||
Optional: []flag.Flag{flag.NamespaceRecorder},
|
||||
})
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
@@ -68,7 +68,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceRecorderFlag},
|
||||
Optional: []flag.Flag{flag.NamespaceRecorder},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
|
||||
@@ -36,32 +36,32 @@ type CreateSubCommand struct {
|
||||
recorder *fv1.Recorder
|
||||
}
|
||||
|
||||
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 {
|
||||
recName := flags.String("name")
|
||||
func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
recName := input.String("name")
|
||||
if len(recName) == 0 {
|
||||
recName = uuid.NewV4().String()
|
||||
}
|
||||
fnName := flags.String("function")
|
||||
triggersOriginal := flags.StringSlice("trigger")
|
||||
fnName := input.String("function")
|
||||
triggersOriginal := input.StringSlice("trigger")
|
||||
|
||||
// Function XOR triggers can be given
|
||||
if len(fnName) == 0 && len(triggersOriginal) == 0 {
|
||||
@@ -104,9 +104,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("spec") {
|
||||
specFile := fmt.Sprintf("recorder-%v.yaml", opts.recorder.Metadata.Name)
|
||||
err := spec.SpecSave(*opts.recorder, specFile)
|
||||
if err != nil {
|
||||
|
||||
@@ -32,35 +32,34 @@ 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", "recorderns", flags)
|
||||
if err != nil {
|
||||
return err
|
||||
func (opts *DeleteSubCommand) complete(input cli.Input) error {
|
||||
opts.metadata = &metav1.ObjectMeta{
|
||||
Name: input.String("name"),
|
||||
Namespace: input.String("recorderns"),
|
||||
}
|
||||
opts.metadata = m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) run(flags cli.Input) error {
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) error {
|
||||
err := opts.client.RecorderDelete(opts.metadata)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting recorder")
|
||||
|
||||
@@ -34,27 +34,27 @@ type GetSubCommand struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func Get(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Get(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := GetSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *GetSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) complete(flags cli.Input) error {
|
||||
opts.name = flags.String("name")
|
||||
func (opts *GetSubCommand) complete(input cli.Input) error {
|
||||
opts.name = input.String("name")
|
||||
|
||||
if len(opts.name) <= 0 {
|
||||
return errors.New("need a recorder name, use --name")
|
||||
@@ -62,7 +62,7 @@ func (opts *GetSubCommand) complete(flags cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) run(flags cli.Input) error {
|
||||
func (opts *GetSubCommand) run(input cli.Input) error {
|
||||
recorder, err := opts.client.RecorderGet(&metav1.ObjectMeta{
|
||||
Name: opts.name,
|
||||
Namespace: "default",
|
||||
|
||||
@@ -32,22 +32,22 @@ 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 {
|
||||
return opts.run(flags)
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) run(flags cli.Input) error {
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
recorders, err := opts.client.RecorderList("default")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing recorders")
|
||||
|
||||
@@ -34,33 +34,33 @@ type UpdateSubCommand struct {
|
||||
recorder *fv1.Recorder
|
||||
}
|
||||
|
||||
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 {
|
||||
recName := flags.String("name")
|
||||
enable := flags.Bool("enable")
|
||||
disable := flags.Bool("disable")
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
recName := input.String("name")
|
||||
enable := input.Bool("enable")
|
||||
disable := input.Bool("disable")
|
||||
//retPolicy := flags.String("retention")
|
||||
//evictPolicy := flags.String("eviction")
|
||||
triggers := flags.StringSlice("trigger")
|
||||
function := flags.String("function")
|
||||
triggers := input.StringSlice("trigger")
|
||||
function := input.String("function")
|
||||
|
||||
if enable && disable {
|
||||
return errors.New("Cannot enable and disable a recorder simultaneously.")
|
||||
@@ -134,7 +134,7 @@ 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.RecorderUpdate(opts.recorder)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating recorder")
|
||||
|
||||
Reference in New Issue
Block a user