mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-06 04:21:15 +00:00
44 lines
866 B
Go
44 lines
866 B
Go
// Copyright (c) 2023, SailPoint Technologies, Inc. All rights reserved.
|
|
package terminal
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"syscall"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
type Term struct{}
|
|
|
|
type Terminal interface {
|
|
PromptPassword(promptMsg string) (string, error)
|
|
}
|
|
|
|
// PromptPassword prompts user to enter password and then returns it
|
|
func (c *Term) PromptPassword(promptMsg string) (string, error) {
|
|
fmt.Print(promptMsg)
|
|
bytePassword, err := term.ReadPassword(int(syscall.Stdin))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
fmt.Println()
|
|
return strings.TrimSpace(string(bytePassword)), nil
|
|
}
|
|
|
|
// InputPrompt receives a string value using the label
|
|
func InputPrompt(label string) string {
|
|
var s string
|
|
r := bufio.NewReader(os.Stdin)
|
|
for {
|
|
fmt.Fprint(os.Stderr, label+" ")
|
|
s, _ = r.ReadString('\n')
|
|
if s != "" {
|
|
break
|
|
}
|
|
}
|
|
return strings.TrimSpace(s)
|
|
}
|