Skip to content

Commit

Permalink
Fixing the CLI decision error handling to avoid lint errors
Browse files Browse the repository at this point in the history
Fixing the CLI decision error handling to avoid lint errors

Signed-off-by: liranmauda <[email protected]>
(cherry picked from commit 10d81d1)
  • Loading branch information
liranmauda committed Jan 12, 2025
1 parent f31fdaf commit 60204c9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/backingstore/backingstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ func createCommon(cmd *cobra.Command, args []string, storeType nbv1.StoreType, p
log.Printf("Found a Secret in the system with the same credentials (%s)", suggestedSecret.Name)
log.Printf("Note that using more then one secret with the same credentials is not supported")
log.Printf("do you want to use it for this Backingstore? y/n")
fmt.Scanln(&decision)
if _, err := fmt.Scanln(&decision); err != nil {
log.Fatalf(`❌ Invalid input, please select y/n`)
}
if strings.ToLower(decision) == "y" {
log.Printf("Will use %s as the Backingstore %s Secret", suggestedSecret.Name, backStore.Name)
err := util.SetBackingStoreSecretRef(backStore, &corev1.SecretReference{
Expand All @@ -407,8 +409,6 @@ func createCommon(cmd *cobra.Command, args []string, storeType nbv1.StoreType, p
}
} else if strings.ToLower(decision) == "n" {
log.Fatalf("Not creating Backingstore")
} else {
log.Fatalf(`❌ Invalid input, please select y/n`)
}
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,21 @@ func RunUninstall(cmd *cobra.Command, args []string) {
if cleanup {
var decision string

log.Printf("--cleanup removes the CRDs and affecting all noobaa instances, are you sure? y/n ")
for {
log.Printf("--cleanup removes the CRDs and affecting all noobaa instances, are you sure? y/n ")
fmt.Scanln(&decision)
if _, err := fmt.Scanln(&decision); err != nil {
log.Printf(`are you sure? y/n`)
}

if decision == "y" {
log.Printf("Will remove CRD (cluster scope)")
break
} else if decision == "n" {
return
log.Printf("Will not uninstall as remove CRD (cluster scope) was declined.")
log.Fatalf("In order to uninstall agree to remove CRD or remove the --cleanup flag.")
}
}
}

system.RunSystemVersionsStatus(cmd, args)
log.Printf("Namespace: %s", options.Namespace)
log.Printf("")
Expand Down
6 changes: 3 additions & 3 deletions pkg/namespacestore/namespacestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ func createCommon(cmd *cobra.Command, args []string, storeType nbv1.NSType, popu
log.Printf("Found a Secret in the system with the same credentials (%s)", suggestedSecret.Name)
log.Printf("Note that using more then one secret with the same credentials is not supported")
log.Printf("do you want to use it for this Namespacestore? y/n")
fmt.Scanln(&decision)
if _, err := fmt.Scanln(&decision); err != nil {
log.Fatalf(`❌ Invalid input, please select y/n`)
}
if strings.ToLower(decision) == "y" {
log.Printf("Will use %s as the Namespacestore Secret", suggestedSecret.Name)
err := util.SetNamespaceStoreSecretRef(namespaceStore, &corev1.SecretReference{
Expand All @@ -382,8 +384,6 @@ func createCommon(cmd *cobra.Command, args []string, storeType nbv1.NSType, popu
}
} else if strings.ToLower(decision) == "n" {
log.Fatalf("Not creating Namespacestore")
} else {
log.Fatalf(`❌ Invalid input, please select y/n`)
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/noobaaaccount/noobaaaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ func RunRegenerate(cmd *cobra.Command, args []string) {
log.Printf("are you sure? y/n")

for {
fmt.Scanln(&decision)
if _, err := fmt.Scanln(&decision); err != nil {
log.Printf(`are you sure? y/n`)
}
if decision == "y" {
break
} else if decision == "n" {
Expand Down
4 changes: 3 additions & 1 deletion pkg/obc/obc.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ func RunRegenerate(cmd *cobra.Command, args []string) {
log.Printf("are you sure? y/n")

for {
fmt.Scanln(&decision)
if _, err := fmt.Scanln(&decision); err != nil {
log.Printf(`are you sure? y/n`)
}
if decision == "y" {
break
} else if decision == "n" {
Expand Down

0 comments on commit 60204c9

Please sign in to comment.