Skip to content

Commit af83f5d

Browse files
author
Jeff McCormick
committed
add ability to have different confirmation messages in pgo, also remove the confirmation from the pgo backup command as not necessary
1 parent 1788178 commit af83f5d

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

pgo/cmd/backup.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
log "github.com/Sirupsen/logrus"
2424
crv1 "github.com/crunchydata/postgres-operator/apis/cr/v1"
2525
msgs "github.com/crunchydata/postgres-operator/apiservermsgs"
26-
"github.com/crunchydata/postgres-operator/pgo/util"
2726
"github.com/spf13/cobra"
2827
"net/http"
2928
"os"
@@ -39,11 +38,7 @@ var backupCmd = &cobra.Command{
3938
if len(args) == 0 && Selector == "" {
4039
fmt.Println(`You must specify the cluster to backup or a selector flag.`)
4140
} else {
42-
if util.AskForConfirmation(NoPrompt) {
43-
createBackup(args)
44-
} else {
45-
fmt.Println("Aborting...")
46-
}
41+
createBackup(args)
4742
}
4843

4944
},

pgo/cmd/delete.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var deleteIngestCmd = &cobra.Command{
9999
if len(args) == 0 {
100100
log.Error("a ingest name is required for this command")
101101
} else {
102-
if util.AskForConfirmation(NoPrompt) {
102+
if util.AskForConfirmation(NoPrompt, "") {
103103
deleteIngest(args)
104104
} else {
105105
fmt.Println("Aborting...")
@@ -117,7 +117,7 @@ var deleteUpgradeCmd = &cobra.Command{
117117
if len(args) == 0 {
118118
log.Error("a database or cluster name is required for this command")
119119
} else {
120-
if util.AskForConfirmation(NoPrompt) {
120+
if util.AskForConfirmation(NoPrompt, "") {
121121
deleteUpgrade(args)
122122
} else {
123123
fmt.Println("Aborting...")
@@ -135,7 +135,7 @@ var deleteBackupCmd = &cobra.Command{
135135
if len(args) == 0 {
136136
log.Error("a database or cluster name is required for this command")
137137
} else {
138-
if util.AskForConfirmation(NoPrompt) {
138+
if util.AskForConfirmation(NoPrompt, "") {
139139
deleteBackup(args)
140140
} else {
141141
fmt.Println("Aborting...")
@@ -157,7 +157,7 @@ var deleteUserCmd = &cobra.Command{
157157
} else if Selector == "" {
158158
log.Error("a selector is required for this command")
159159
} else {
160-
if util.AskForConfirmation(NoPrompt) {
160+
if util.AskForConfirmation(NoPrompt, "") {
161161
deleteUser(args[0])
162162

163163
} else {
@@ -177,7 +177,7 @@ var deleteClusterCmd = &cobra.Command{
177177
if len(args) == 0 && Selector == "" {
178178
log.Error("a cluster name or selector is required for this command")
179179
} else {
180-
if util.AskForConfirmation(NoPrompt) {
180+
if util.AskForConfirmation(NoPrompt, "") {
181181
deleteCluster(args)
182182

183183
} else {
@@ -196,7 +196,7 @@ var deletePolicyCmd = &cobra.Command{
196196
if len(args) == 0 {
197197
log.Error("a policy name is required for this command")
198198
} else {
199-
if util.AskForConfirmation(NoPrompt) {
199+
if util.AskForConfirmation(NoPrompt, "") {
200200
deletePolicy(args)
201201
} else {
202202
fmt.Println("Aborting...")

pgo/cmd/failover.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var failoverCmd = &cobra.Command{
4040
} else {
4141
if Query {
4242
createFailover(args)
43-
} else if util.AskForConfirmation(NoPrompt) {
43+
} else if util.AskForConfirmation(NoPrompt, "") {
4444
if Target == "" {
4545
fmt.Println(`--target is required for failover.`)
4646
return

pgo/cmd/upgrade.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ func validateCreateUpdate(args []string) error {
190190
var err error
191191

192192
if UpgradeType == MajorUpgrade {
193-
if util.AskForConfirmation(NoPrompt) {
193+
if util.AskForConfirmation(NoPrompt, "") {
194194
} else {
195-
fmt.Println(`Aborting...`)
195+
fmt.Println("Aborting...")
196196
os.Exit(2)
197197
}
198198

pgo/util/confirmation.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ import (
2424
// confirmations. If the input is not recognized, it will ask again. The function does not return
2525
// until it gets a valid response from the user. Typically, you should use fmt to print out a question
2626
// before calling AskForConfirmation. E.g. fmt.Println("WARNING: Are you sure? (yes/no)")
27-
func AskForConfirmation(NoPrompt bool) bool {
27+
func AskForConfirmation(NoPrompt bool, msg string) bool {
2828
var response string
2929

3030
if NoPrompt {
3131
return true
3232
}
33-
fmt.Print("WARNING - This is destructive: Are you sure? (yes/no): ")
33+
if msg == "" {
34+
fmt.Print("WARNING - This is destructive: Are you sure? (yes/no): ")
35+
} else {
36+
fmt.Print("WARNING - " + msg + " (yes/no): ")
37+
}
3438

3539
_, err := fmt.Scanln(&response)
3640
if err != nil {
3741
fmt.Println("Please type yes or no and then press enter:")
38-
return AskForConfirmation(NoPrompt)
42+
return AskForConfirmation(NoPrompt, msg)
3943
}
4044
okayResponses := []string{"y", "Y", "yes", "Yes", "YES"}
4145
nokayResponses := []string{"n", "N", "no", "No", "NO", ""}
@@ -45,7 +49,7 @@ func AskForConfirmation(NoPrompt bool) bool {
4549
return false
4650
} else {
4751
fmt.Println("Please type yes or no and then press enter:")
48-
return AskForConfirmation(NoPrompt)
52+
return AskForConfirmation(NoPrompt, msg)
4953
}
5054
}
5155

0 commit comments

Comments
 (0)