mirror of
https://github.com/DeBrosOfficial/orama.git
synced 2026-03-17 11:06:57 +00:00
34 lines
892 B
Go
34 lines
892 B
Go
package shared
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// Confirm prompts the user for yes/no confirmation. Returns true if user confirms.
|
|
func Confirm(prompt string) bool {
|
|
fmt.Printf("%s (y/N): ", prompt)
|
|
reader := bufio.NewReader(os.Stdin)
|
|
response, _ := reader.ReadString('\n')
|
|
response = strings.ToLower(strings.TrimSpace(response))
|
|
return response == "y" || response == "yes"
|
|
}
|
|
|
|
// ConfirmExact prompts the user to type an exact string to confirm. Returns true if matched.
|
|
func ConfirmExact(prompt, expected string) bool {
|
|
fmt.Printf("%s: ", prompt)
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
scanner.Scan()
|
|
return strings.TrimSpace(scanner.Text()) == expected
|
|
}
|
|
|
|
// RequireRoot exits with an error if the current user is not root.
|
|
func RequireRoot() {
|
|
if os.Geteuid() != 0 {
|
|
fmt.Fprintf(os.Stderr, "Error: This command must be run as root (use sudo)\n")
|
|
os.Exit(1)
|
|
}
|
|
}
|