From 80b66434c0f4166ce7d34c97b07565925f7b2c08 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Tue, 3 Apr 2018 20:43:42 -0700 Subject: [PATCH] move getting client into Complete() Signed-off-by: Steve Kriss --- pkg/cmd/cli/restore/create.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/cli/restore/create.go b/pkg/cmd/cli/restore/create.go index cd0e98562..503f7eaac 100644 --- a/pkg/cmd/cli/restore/create.go +++ b/pkg/cmd/cli/restore/create.go @@ -47,7 +47,7 @@ func NewCreateCommand(f client.Factory, use string) *cobra.Command { ark restore create --from-backup backup-1`, Args: cobra.MaximumNArgs(1), Run: func(c *cobra.Command, args []string) { - cmd.CheckError(o.Complete(args)) + cmd.CheckError(o.Complete(args, f)) cmd.CheckError(o.Validate(c, args, f)) cmd.CheckError(o.Run(c, f)) }, @@ -113,27 +113,31 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto return err } - client, err := f.Client() - if err != nil { - return err + if o.client == nil { + // This should never happen + return errors.New("Ark client is not set; unable to proceed") } - o.client = client - _, err = o.client.ArkV1().Backups(f.Namespace()).Get(o.BackupName, metav1.GetOptions{}) - if err != nil { + if _, err := o.client.ArkV1().Backups(f.Namespace()).Get(o.BackupName, metav1.GetOptions{}); err != nil { return err } return nil } -func (o *CreateOptions) Complete(args []string) error { +func (o *CreateOptions) Complete(args []string, f client.Factory) error { if len(args) == 1 { o.RestoreName = args[0] } else { o.RestoreName = fmt.Sprintf("%s-%s", o.BackupName, time.Now().Format("20060102150405")) } + client, err := f.Client() + if err != nil { + return err + } + o.client = client + return nil }