aboutsummaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorJosh Bialkowski <josh.bialkowski@gmail.com>2019-11-22 22:34:19 -0800
committerJosh Bialkowski <josh.bialkowski@gmail.com>2019-12-18 07:42:16 -0800
commitcd889572f7870a62758240b323a9086a76c5120a (patch)
tree2d8a210632e3b82517cd259760e94e375ebff123 /input
parent7657a38ff20a7b3b2dbec5e6c981038c871f46e7 (diff)
downloadgit-bug-cd889572f7870a62758240b323a9086a76c5120a.tar.gz
codereview #2: some cleanup, correct use of nothing-events
* return error, don't panic * skipping status export is an error * use switch in config.go * move PromptPassword to input * move client construction into getIdentityClient * use non-pointer context throughout client since it is an interface * remove some TODOs * don't emit multiple nothing-events, just one per bug only if nothing happened. * rename EditBody to EditCreateComment * add configuration notes about additional values * store bug id map in a dictionary in the config * some fixes from testing
Diffstat (limited to 'input')
-rw-r--r--input/prompt.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/input/prompt.go b/input/prompt.go
index 6036c062..72910575 100644
--- a/input/prompt.go
+++ b/input/prompt.go
@@ -5,6 +5,10 @@ import (
"fmt"
"os"
"strings"
+ "syscall"
+
+ "github.com/MichaelMure/git-bug/util/interrupt"
+ "golang.org/x/crypto/ssh/terminal"
)
func PromptValue(name string, preValue string) (string, error) {
@@ -42,3 +46,35 @@ func promptValue(name string, preValue string, required bool) (string, error) {
return line, nil
}
}
+
+// PromptPassword performs interactive input collection to get the user password
+// while halting echo on the controlling terminal.
+func PromptPassword() (string, error) {
+ termState, err := terminal.GetState(int(syscall.Stdin))
+ if err != nil {
+ return "", err
+ }
+
+ cancel := interrupt.RegisterCleaner(func() error {
+ return terminal.Restore(int(syscall.Stdin), termState)
+ })
+ defer cancel()
+
+ for {
+ fmt.Print("password: ")
+ bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
+ // new line for coherent formatting, ReadPassword clip the normal new line
+ // entered by the user
+ fmt.Println()
+
+ if err != nil {
+ return "", err
+ }
+
+ if len(bytePassword) > 0 {
+ return string(bytePassword), nil
+ }
+
+ fmt.Println("password is empty")
+ }
+}