Skip to content

Commit

Permalink
add func to ask confirmations
Browse files Browse the repository at this point in the history
Signed-off-by: Thiago Pagotto <pagottoo@gmail.com>
  • Loading branch information
pagottoo committed Jul 25, 2022
1 parent d79ad3b commit 725d26e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pkg

import (
"bufio"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -153,3 +154,24 @@ func CreateFullPath(p string) (*os.File, error) {
}
return os.Create(p)
}

func AskForConfirmation(s string) bool {
reader := bufio.NewReader(os.Stdin)

for {
fmt.Printf("%s [y/n]: ", s)

response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}

response = strings.ToLower(strings.TrimSpace(response))

if response == "y" || response == "yes" {
return true
} else if response == "n" || response == "no" {
return false
}
}
}

0 comments on commit 725d26e

Please sign in to comment.