mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 06:54:32 +02:00
-y/--yes flag for non-interactive mode (fixes #46)
Also makes Modrinth auto-accept search results with only 1 result, to be consistent with CurseForge.
This commit is contained in:
28
cmdshared/prompt.go
Normal file
28
cmdshared/prompt.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package cmdshared
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func PromptYesNo(prompt string) bool {
|
||||
fmt.Print(prompt)
|
||||
if viper.GetBool("non-interactive") {
|
||||
fmt.Println("Y (non-interactive mode)")
|
||||
return true
|
||||
}
|
||||
answer, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to prompt user: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ansNormal := strings.ToLower(strings.TrimSpace(answer))
|
||||
if len(ansNormal) > 0 && ansNormal[0] == 'n' {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user