diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/bgentry/speakeasy/speakeasy.go | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip |
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/bgentry/speakeasy/speakeasy.go')
-rw-r--r-- | vendor/github.com/bgentry/speakeasy/speakeasy.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/bgentry/speakeasy/speakeasy.go b/vendor/github.com/bgentry/speakeasy/speakeasy.go new file mode 100644 index 0000000..71c1dd1 --- /dev/null +++ b/vendor/github.com/bgentry/speakeasy/speakeasy.go | |||
@@ -0,0 +1,49 @@ | |||
1 | package speakeasy | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "io" | ||
6 | "os" | ||
7 | "strings" | ||
8 | ) | ||
9 | |||
10 | // Ask the user to enter a password with input hidden. prompt is a string to | ||
11 | // display before the user's input. Returns the provided password, or an error | ||
12 | // if the command failed. | ||
13 | func Ask(prompt string) (password string, err error) { | ||
14 | return FAsk(os.Stdout, prompt) | ||
15 | } | ||
16 | |||
17 | // FAsk is the same as Ask, except it is possible to specify the file to write | ||
18 | // the prompt to. If 'nil' is passed as the writer, no prompt will be written. | ||
19 | func FAsk(wr io.Writer, prompt string) (password string, err error) { | ||
20 | if wr != nil && prompt != "" { | ||
21 | fmt.Fprint(wr, prompt) // Display the prompt. | ||
22 | } | ||
23 | password, err = getPassword() | ||
24 | |||
25 | // Carriage return after the user input. | ||
26 | if wr != nil { | ||
27 | fmt.Fprintln(wr, "") | ||
28 | } | ||
29 | return | ||
30 | } | ||
31 | |||
32 | func readline() (value string, err error) { | ||
33 | var valb []byte | ||
34 | var n int | ||
35 | b := make([]byte, 1) | ||
36 | for { | ||
37 | // read one byte at a time so we don't accidentally read extra bytes | ||
38 | n, err = os.Stdin.Read(b) | ||
39 | if err != nil && err != io.EOF { | ||
40 | return "", err | ||
41 | } | ||
42 | if n == 0 || b[0] == '\n' { | ||
43 | break | ||
44 | } | ||
45 | valb = append(valb, b[0]) | ||
46 | } | ||
47 | |||
48 | return strings.TrimSuffix(string(valb), "\r"), nil | ||
49 | } | ||