Skip to content

Commit d63e477

Browse files
author
Mario L Gutierrez
committed
add Prompt and PromptPassword
1 parent e62bbbf commit d63e477

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ Inside("somedir", func() {
226226
})
227227
```
228228

229+
## User Input
230+
231+
To get plain string
232+
233+
```go
234+
user := Prompt("user: ")
235+
```
236+
237+
To get password
238+
239+
```go
240+
password := PromptPassword("password: ")
241+
```
242+
229243
## Godofile Run-Time Environment
230244

231245
To specify whether to inherit from parent's process environment,

exec.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package godo
22

33
import (
4+
"bufio"
5+
"fmt"
46
"os"
57
"path"
68
"strconv"
79
"strings"
810

11+
"github.com/howeyc/gopass"
912
"github.com/mgutz/str"
1013
)
1114

@@ -161,3 +164,17 @@ func Inside(dir string, lambda func()) error {
161164
lambda()
162165
return nil
163166
}
167+
168+
// Prompt prompts user for input with default value.
169+
func Prompt(prompt string) string {
170+
reader := bufio.NewReader(os.Stdin)
171+
fmt.Print(prompt)
172+
text, _ := reader.ReadString('\n')
173+
return text
174+
}
175+
176+
// PromptPassword prompts user for password input.
177+
func PromptPassword(prompt string) string {
178+
fmt.Printf(prompt)
179+
return string(gopass.GetPasswd())
180+
}

0 commit comments

Comments
 (0)