mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Improve confirmation prompts
This commit is contained in:
+48
-33
@@ -433,15 +433,12 @@ func installPackages() {
|
|||||||
|
|
||||||
// Confirmation Prompt
|
// Confirmation Prompt
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
prompt := "Do you wish to install this package?"
|
||||||
if len(operation.Actions) == 1 {
|
if len(operation.Actions) != 1 {
|
||||||
fmt.Printf("Do you wish to install this package? [y\\N] ")
|
prompt = fmt.Sprintf("Do you wish to install all %d packages?", len(operation.Actions))
|
||||||
} else {
|
|
||||||
fmt.Printf("Do you wish to install these %d packages? [y\\N] ", len(operation.Actions))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
text, _ := reader.ReadString('\n')
|
if !showConfirmationPrompt(prompt, false) {
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
|
||||||
fmt.Println("Cancelling package installation...")
|
fmt.Println("Cancelling package installation...")
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
@@ -467,11 +464,7 @@ func installPackages() {
|
|||||||
|
|
||||||
// Confirmation Prompt
|
// Confirmation Prompt
|
||||||
if sourcePackagesShown > 0 && !yesAll {
|
if sourcePackagesShown > 0 && !yesAll {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
if !showConfirmationPrompt("Do you wish to continue?", false) {
|
||||||
fmt.Printf("Are you sure you wish to continue? [y\\N] ")
|
|
||||||
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
|
||||||
fmt.Println("Cancelling package installation...")
|
fmt.Println("Cancelling package installation...")
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
@@ -556,10 +549,12 @@ func removePackages() {
|
|||||||
|
|
||||||
// Confirmation Prompt
|
// Confirmation Prompt
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
fmt.Printf("Are you sure you wish to remove all %d packages? [y\\N] ", len(operation.Actions))
|
prompt := "Do you wish to remove this package?"
|
||||||
reader := bufio.NewReader(os.Stdin)
|
if len(operation.Actions) != 1 {
|
||||||
text, _ := reader.ReadString('\n')
|
prompt = fmt.Sprintf("Do you wish to remove all %d packages?", len(operation.Actions))
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
}
|
||||||
|
|
||||||
|
if !showConfirmationPrompt(prompt, false) {
|
||||||
fmt.Println("Cancelling package removal...")
|
fmt.Println("Cancelling package removal...")
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
@@ -667,10 +662,12 @@ func doCleanup() {
|
|||||||
|
|
||||||
// Confirmation Prompt
|
// Confirmation Prompt
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
fmt.Printf("Are you sure you wish to remove all %d packages? [y\\N] ", len(operation.Actions))
|
prompt := "Do you wish to remove this package?"
|
||||||
reader := bufio.NewReader(os.Stdin)
|
if len(operation.Actions) != 1 {
|
||||||
text, _ := reader.ReadString('\n')
|
prompt = fmt.Sprintf("Do you wish to remove all %d packages?", len(operation.Actions))
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
}
|
||||||
|
|
||||||
|
if !showConfirmationPrompt(prompt, false) {
|
||||||
fmt.Println("Cancelling package removal...")
|
fmt.Println("Cancelling package removal...")
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
@@ -720,10 +717,7 @@ func syncDatabases() {
|
|||||||
|
|
||||||
// Confirmation Prompt
|
// Confirmation Prompt
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
fmt.Printf("Are you sure you wish to sync all databases? [y\\N] ")
|
if !showConfirmationPrompt("Do you wish to sync all databases?", false) {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
|
||||||
fmt.Println("Cancelling database synchronization...")
|
fmt.Println("Cancelling database synchronization...")
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
@@ -797,10 +791,12 @@ func updatePackages() {
|
|||||||
|
|
||||||
// Confirmation Prompt
|
// Confirmation Prompt
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
fmt.Printf("Are you sure you wish to update all %d packages? [y\\N] ", len(operation.Actions))
|
prompt := "Do you wish to update this package?"
|
||||||
reader := bufio.NewReader(os.Stdin)
|
if len(operation.Actions) != 1 {
|
||||||
text, _ := reader.ReadString('\n')
|
prompt = fmt.Sprintf("Do you wish to update all %d packages?", len(operation.Actions))
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
}
|
||||||
|
|
||||||
|
if !showConfirmationPrompt(prompt, false) {
|
||||||
fmt.Println("Cancelling package update...")
|
fmt.Println("Cancelling package update...")
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
@@ -826,11 +822,7 @@ func updatePackages() {
|
|||||||
|
|
||||||
// Confirmation Prompt
|
// Confirmation Prompt
|
||||||
if sourcePackagesShown > 0 && !yesAll {
|
if sourcePackagesShown > 0 && !yesAll {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
if !showConfirmationPrompt("Do you wish to continue?", false) {
|
||||||
fmt.Printf("Are you sure you wish to continue? [y\\N] ")
|
|
||||||
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
|
||||||
fmt.Println("Cancelling package installation...")
|
fmt.Println("Cancelling package installation...")
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
@@ -1208,3 +1200,26 @@ func isFlagSet(flagSet *flag.FlagSet, name string) bool {
|
|||||||
})
|
})
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showConfirmationPrompt(prompt string, defaultTo bool) bool {
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
if defaultTo {
|
||||||
|
fmt.Printf("%s [Y/n] ", prompt)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%s [y/N] ", prompt)
|
||||||
|
}
|
||||||
|
|
||||||
|
text, _ := reader.ReadString('\n')
|
||||||
|
text = strings.TrimSpace(text)
|
||||||
|
|
||||||
|
if len(text) > 0 {
|
||||||
|
switch text[0] {
|
||||||
|
case 'y', 'Y':
|
||||||
|
return true
|
||||||
|
case 'n', 'N':
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultTo
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user