From adc011f01696f370da8d05ad2580e70d4f6af8f6 Mon Sep 17 00:00:00 2001 From: harsh082ip Date: Wed, 10 Jul 2024 03:59:47 +0530 Subject: [PATCH] fix: reconsider behavior when providing a value lower than 500 for bucket size #394 --- cmd/objectstore/objectstore.go | 3 ++- cmd/objectstore/objectstore_create.go | 29 ++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cmd/objectstore/objectstore.go b/cmd/objectstore/objectstore.go index 541665e0..a0314b52 100644 --- a/cmd/objectstore/objectstore.go +++ b/cmd/objectstore/objectstore.go @@ -45,10 +45,11 @@ func init() { ObjectStoreCmd.AddCommand(objectStoreCredentialCmd) //Flags for create cmd - objectStoreCreateCmd.Flags().Int64VarP(&bucketSize, "size", "s", 500, "Size of the Object store") + objectStoreCreateCmd.Flags().Int64VarP(&bucketSize, "size", "s", 500, "Size of the Object store in GB (minimum: 500)") objectStoreCreateCmd.Flags().StringVarP(&owner, "owner-name", "n", "", "Name of Owner of the Object store. You can reference name of any civo object store credential created before") objectStoreCreateCmd.Flags().StringVarP(&owner, "owner-access-key", "a", "", "Access Key ID of Owner of the Object store. You can reference name of any civo object store credential created before") objectStoreCreateCmd.Flags().BoolVarP(&waitOS, "wait", "w", false, "a simple flag (e.g. --wait) that will cause the CLI to spin and wait for the Object Store to be ready") + objectStoreCreateCmd.Flags().BoolVarP(&yesFlag, "yes", "y", false, "Automatically agree to any confirmation prompts") //Flags for update cmd objectStoreUpdateCmd.Flags().Int64VarP(&bucketSize, "size", "s", 500, "Size of the object store") diff --git a/cmd/objectstore/objectstore_create.go b/cmd/objectstore/objectstore_create.go index e3cc4ef2..25250e9f 100644 --- a/cmd/objectstore/objectstore_create.go +++ b/cmd/objectstore/objectstore_create.go @@ -16,6 +16,7 @@ import ( var bucketSize int64 var owner string var waitOS bool +var yesFlag bool var objectStoreCreateCmd = &cobra.Command{ Use: "create", @@ -34,7 +35,6 @@ var objectStoreCreateCmd = &cobra.Command{ os.Exit(1) } objectStoreName = args[0] - } else { objectStoreName = utility.RandomName() } @@ -61,21 +61,22 @@ var objectStoreCreateCmd = &cobra.Command{ } if bucketSize < 500 { - utility.YellowConfirm("The minimum size to create an object store is 500 GB. Would you like to create an %s of 500 GB? (y/n) ? ", utility.Green("object store")) - _, err := utility.UserAccepts(os.Stdin) - if err != nil { - utility.Error("Unable to parse the input: %s", err) - os.Exit(1) - } - bucketSize = 500 + utility.Error("The minimum size to create an object store is 500 GB. Please provide a valid size.") + os.Exit(1) } else if bucketSize%500 != 0 { - utility.YellowConfirm("The size to create an object store must be a multiple of 500. Would you like to create an %s of %d GB instead? (y/n) ? ", utility.Green("object store"), bucketSize+(500-bucketSize%500)) - _, err := utility.UserAccepts(os.Stdin) - if err != nil { - utility.Error("Unable to parse the input: %s", err) - os.Exit(1) + if !yesFlag { + utility.YellowConfirm("The size to create an object store must be a multiple of 500. Would you like to create an %s of %d GB instead? (y/n) ? ", utility.Green("object store"), bucketSize+(500-bucketSize%500)) + accept, err := utility.UserAccepts(os.Stdin) + if err != nil { + utility.Error("Unable to parse the input: %s", err) + os.Exit(1) + } + if !accept { + os.Exit(0) + } + } else { + bucketSize = bucketSize + (500 - bucketSize%500) } - bucketSize = bucketSize + (500 - bucketSize%500) } var credential *civogo.ObjectStoreCredential