Skip to content

Commit ddd1601

Browse files
thcyronthetechnick
authored andcommitted
Do not echo token when creating a context (#85)
1 parent 22c6dda commit ddd1601

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master
44

55
* Print dates in local time
6+
* Do not echo token when creating a context
67

78
## v1.2.0
89

context_create.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package cli
22

33
import (
4-
"bufio"
4+
"bytes"
55
"errors"
66
"fmt"
7-
"os"
87
"strings"
8+
"syscall"
99

1010
"github.com/spf13/cobra"
11+
"golang.org/x/crypto/ssh/terminal"
1112
)
1213

1314
func newContextCreateCommand(cli *CLI) *cobra.Command {
@@ -35,16 +36,16 @@ func runContextCreate(cli *CLI, cmd *cobra.Command, args []string) error {
3536
return errors.New("name already used")
3637
}
3738

38-
r := bufio.NewReader(os.Stdin)
3939
context := &ConfigContext{Name: name}
4040

4141
for {
4242
fmt.Printf("Token: ")
43-
token, err := r.ReadString('\n')
43+
btoken, err := terminal.ReadPassword(int(syscall.Stdin))
44+
fmt.Print("\n")
4445
if err != nil {
4546
return err
4647
}
47-
token = strings.TrimSpace(token)
48+
token := string(bytes.TrimSpace(btoken))
4849
if token == "" {
4950
continue
5051
}

0 commit comments

Comments
 (0)