github.com/supabase/cli@v1.168.1/internal/utils/credentials/input.go (about) 1 package credentials 2 3 import ( 4 "bytes" 5 "fmt" 6 "io" 7 "os" 8 9 "golang.org/x/term" 10 ) 11 12 func PromptMasked(stdin *os.File) string { 13 // Start a new line after reading input 14 defer fmt.Println() 15 // Copy if stdin is piped: https://stackoverflow.com/a/26567513 16 if !term.IsTerminal(int(stdin.Fd())) { 17 var buf bytes.Buffer 18 if _, err := io.Copy(&buf, stdin); err != nil { 19 return "" 20 } 21 return buf.String() 22 } 23 // Read with masked tokens 24 bytepw, err := term.ReadPassword(int(stdin.Fd())) 25 if err != nil { 26 fmt.Fprintln(os.Stderr, "Failed to read password:", err) 27 return "" 28 } 29 return string(bytepw) 30 }