From df8a9559d332b7c27ef6e30a37f178a4a303394b Mon Sep 17 00:00:00 2001 From: knbr13 Date: Thu, 1 Feb 2024 18:27:57 +0200 Subject: [PATCH] simplify getting user input functionality --- input.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/input.go b/input.go index 24526bd..274d4e9 100644 --- a/input.go +++ b/input.go @@ -9,28 +9,18 @@ import ( "github.com/gookit/color" ) -type validator func(string) bool - -func getUserInput(reader *bufio.Reader, prompt string, fn validator) string { +func getPathFromUser(reader *bufio.Reader) string { for { - fmt.Print(prompt) + fmt.Print("enter the folder path to scan for Git repositories: ") input, err := reader.ReadString('\n') if err != nil { fmt.Fprintf(os.Stderr, "gitcs: error reading input: %s\n", err.Error()) os.Exit(1) } - if fn(input) { + input = strings.TrimSpace(input) + if isValidFolderPath(input) { return input } - fmt.Println(color.Yellow.Sprint("invalid input. Please try again!")) + fmt.Println(color.Yellow.Sprintf("gitcs: path %q is not found, please enter a valid folder path", input)) } } - -func getPathFromUser(reader *bufio.Reader) string { - folder := getUserInput(reader, "Enter the folder path to scan for Git repositories: ", func(s string) bool { - return isValidFolderPath(strings.ToLower(strings.TrimSpace(s))) - }) - folder = strings.ToLower(strings.TrimSpace(folder)) - - return folder -}