File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff 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
231245To specify whether to inherit from parent's process environment,
Original file line number Diff line number Diff line change 11package godo
22
33import (
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+ }
You can’t perform that action at this time.
0 commit comments