mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-08 22:23:15 +00:00
use cobra's arg-count validation & call Complete() before Validate()
Signed-off-by: Steve Kriss <steve@heptio.com>
This commit is contained in:
@@ -45,9 +45,10 @@ func NewCreateCommand(f client.Factory, use string) *cobra.Command {
|
||||
|
||||
# create a restore with a default name ("backup-1-<timestamp>") from backup "backup-1"
|
||||
ark restore create --from-backup backup-1`,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
cmd.CheckError(o.Validate(c, args, f))
|
||||
cmd.CheckError(o.Complete(args))
|
||||
cmd.CheckError(o.Validate(c, args, f))
|
||||
cmd.CheckError(o.Run(c, f))
|
||||
},
|
||||
}
|
||||
@@ -108,10 +109,6 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto
|
||||
return errors.New("--from-backup is required")
|
||||
}
|
||||
|
||||
if len(args) > 1 {
|
||||
return errors.New("you may specify at most one argument, the restore's name")
|
||||
}
|
||||
|
||||
if err := output.ValidateFlags(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package restore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@@ -30,12 +29,8 @@ func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: fmt.Sprintf("%s NAME", use),
|
||||
Short: "Delete a restore",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
c.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
arkClient, err := f.Client()
|
||||
cmd.CheckError(err)
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/heptio/ark/pkg/apis/ark/v1"
|
||||
@@ -35,12 +34,8 @@ func NewLogsCommand(f client.Factory) *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: "logs RESTORE",
|
||||
Short: "Get restore logs",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
err := errors.New("restore name is required")
|
||||
cmd.CheckError(err)
|
||||
}
|
||||
|
||||
arkClient, err := f.Client()
|
||||
cmd.CheckError(err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user