move backup name validation to Args to run before cluster contact, and validate regardless of --from-schedule

Signed-off-by: samay43 <samayrbhat43@gmail.com>
This commit is contained in:
samay43
2026-08-12 09:51:10 +05:30
parent 7ffdb27aab
commit 164d9343aa
2 changed files with 12 additions and 2 deletions
+11 -1
View File
@@ -46,7 +46,17 @@ func NewCreateCommand(f client.Factory, use string) *cobra.Command {
c := &cobra.Command{
Use: use + " NAME",
Short: "Create a backup",
Args: cobra.MaximumNArgs(1),
Args: func(c *cobra.Command, args []string) error {
if err := cobra.MaximumNArgs(1)(c, args); err != nil {
return err
}
if len(args) == 1 {
if errs := validation.IsDNS1123Subdomain(args[0]); len(errs) > 0 {
return fmt.Errorf("invalid backup name %q: %s", args[0], strings.Join(errs, "; "))
}
}
return nil
},
Run: func(c *cobra.Command, args []string) {
cmd.CheckError(o.Complete(args, f))
cmd.CheckError(o.Validate(c, args, f))
+1 -1
View File
@@ -233,7 +233,7 @@ func TestCreateOptions_OrderedResources(t *testing.T) {
}
func TestCreateCommand(t *testing.T) {
name := "nameToBeCreated"
name := "name-to-be-created"
args := []string{name}
t.Run("create a backup create command with full options except fromSchedule and wait, then run by create option", func(t *testing.T) {