ask_credentials.go 773 B

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package cli // import "miniflux.app/v2/internal/cli"
  4. import (
  5. "bufio"
  6. "errors"
  7. "fmt"
  8. "os"
  9. "strings"
  10. "golang.org/x/term"
  11. )
  12. func askCredentials() (string, string) {
  13. fd := int(os.Stdin.Fd())
  14. if !term.IsTerminal(fd) {
  15. printErrorAndExit(errors.New("this is not an interactive terminal, exiting"))
  16. }
  17. fmt.Print("Enter Username: ")
  18. reader := bufio.NewReader(os.Stdin)
  19. username, _ := reader.ReadString('\n')
  20. fmt.Print("Enter Password: ")
  21. state, _ := term.GetState(fd)
  22. defer term.Restore(fd, state)
  23. bytePassword, _ := term.ReadPassword(fd)
  24. fmt.Print("\n")
  25. return strings.TrimSpace(username), strings.TrimSpace(string(bytePassword))
  26. }