From 7b1625d65f6b6da654720d61b9b6ec500f6a0d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 9 Nov 2020 17:31:32 +0200 Subject: [PATCH] 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. --- maxctrl/lib/core.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/maxctrl/lib/core.js b/maxctrl/lib/core.js index ce753aa2c..58829b102 100644 --- a/maxctrl/lib/core.js +++ b/maxctrl/lib/core.js @@ -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,