Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit 2b6d80f

Browse files
author
Shlomi Noach
authored
Merge pull request #40 from svagner/master
Add interactive password input
2 parents eff9510 + 7acec3a commit 2b6d80f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

go/cmd/ccql/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
"log"
77
"os"
88
"os/user"
9+
"syscall"
910

1011
"github.com/github/ccql/go/logic"
1112
"github.com/github/ccql/go/sql"
1213
"github.com/github/ccql/go/text"
14+
"golang.org/x/crypto/ssh/terminal"
1315

1416
golib_log "github.com/outbrain/golib/log"
1517
"gopkg.in/gcfg.v1"
@@ -35,6 +37,7 @@ func main() {
3537
help := flag.Bool("help", false, "Display usage")
3638
user := flag.String("u", osUser, "MySQL username")
3739
password := flag.String("p", "", "MySQL password")
40+
askPassword := flag.Bool("ask-pass", false, "prompt for MySQL password")
3841
credentialsFile := flag.String("C", "", "Credentials file, expecting [client] scope, with 'user', 'password' fields. Overrides -u and -p")
3942
defaultSchema := flag.String("d", "information_schema", "Default schema to use")
4043
hostsList := flag.String("h", "", "Comma or space delimited list of hosts in hostname[:port] format. If not given, hosts read from stdin")
@@ -105,6 +108,15 @@ func main() {
105108
}
106109
}
107110

111+
if *askPassword {
112+
fmt.Print("Mysql password: ")
113+
passwd, err := terminal.ReadPassword(int(syscall.Stdin))
114+
if err != nil {
115+
log.Fatalf("\nError while get password:", err)
116+
}
117+
*password = string(passwd)
118+
}
119+
108120
if err := logic.QueryHosts(hosts, *user, *password, *defaultSchema, queries, *maxConcurrency, *timeout); err != nil {
109121
os.Exit(1)
110122
}

0 commit comments

Comments
 (0)