Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reconsider behavior when providing a value lower than 500 for bu… #438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/objectstore/objectstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
29 changes: 15 additions & 14 deletions cmd/objectstore/objectstore_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
var bucketSize int64
var owner string
var waitOS bool
var yesFlag bool

var objectStoreCreateCmd = &cobra.Command{
Use: "create",
Expand All @@ -34,7 +35,6 @@ var objectStoreCreateCmd = &cobra.Command{
os.Exit(1)
}
objectStoreName = args[0]

} else {
objectStoreName = utility.RandomName()
}
Expand All @@ -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
Expand Down