MXS-3272: Ask password first

The interactive would give the prompt first before asking for the
password. By copying the code from common.js, the password is always asked
first.
This commit is contained in:
Markus Mäkelä 2020-11-09 17:31:32 +02:00
parent 46dab1e884
commit 7b1625d65f
No known key found for this signature in database
GPG Key ID: 5CE746D557ACC499

View File

@ -14,6 +14,7 @@
var fs = require('fs')
var program = require('yargs');
var inquirer = require('inquirer')
var readlineSync = require('readline-sync')
// Note: The version.js file is generated at configuation time. If you are
// building in-source, manually create the file
@ -120,6 +121,20 @@ program
.demandCommand(1, 'At least one command is required')
.command('*', 'the default command', {}, function(argv) {
if (argv._.length == 0) {
// No password given, ask it from the command line
// TODO: Combine this into the one in common.js
if (argv.password == '') {
if (process.stdin.isTTY) {
argv.password = readlineSync.question('Enter password: ', {
hideEchoBack: true
})
} else {
var line = fs.readFileSync(0)
argv.password = line.toString().trim()
}
}
base_opts = ['--user=' + argv.user,
'--password=' + argv.password,
'--hosts=' + argv.hosts,