use /dev/tty for stdin when specified

This commit is contained in:
AJ ONeal 2018-06-13 10:45:54 -06:00
parent 7d8916f645
commit e57485f794
2 changed files with 17 additions and 12 deletions

View File

@ -16,15 +16,18 @@ var common = require('../lib/cli-common.js');
var argv = process.argv.slice(2); var argv = process.argv.slice(2);
var confIndex = argv.indexOf('--config'); var argIndex = argv.indexOf('--config');
var confpath; var confpath;
var confargs; var useTty;
if (-1 === confIndex) { if (-1 === argIndex) {
confIndex = argv.indexOf('-c'); argIndex = argv.indexOf('-c');
} }
if (-1 !== confIndex) { if (-1 !== argIndex) {
confargs = argv.splice(confIndex, 2); confpath = argv.splice(argIndex, 2)[1];
confpath = confargs[1]; }
argIndex = argv.indexOf('--tty');
if (-1 !== argIndex) {
useTty = argv.splice(argIndex, 1);
} }
function help() { function help() {
@ -69,7 +72,7 @@ function help() {
} }
var verstr = '' + pkg.name + ' v' + pkg.version; var verstr = '' + pkg.name + ' v' + pkg.version;
if (-1 === confIndex) { if (!confpath) {
confpath = path.join(require('os').homedir(), '.config/telebit/telebit.yml'); confpath = path.join(require('os').homedir(), '.config/telebit/telebit.yml');
verstr += ' (--config "' + confpath + '")'; verstr += ' (--config "' + confpath + '")';
} }
@ -87,10 +90,12 @@ if (!confpath || /^--/.test(confpath)) {
function askForConfig(answers, mainCb) { function askForConfig(answers, mainCb) {
answers = answers || {}; answers = answers || {};
//console.log("Please create a config file at '" + confpath + "' or specify --config /path/to/config"); //console.log("Please create a config file at '" + confpath + "' or specify --config /path/to/config");
var fs = require('fs');
var stdin = useTty ? process.stdin : fs.createReadStream('/dev/tty');
var readline = require('readline'); var readline = require('readline');
var rl = readline.createInterface({ var rl = readline.createInterface({
input: process.stdin, input: stdin
output: process.stdout , output: process.stdout
}); });
// NOTE: Use of setTimeout // NOTE: Use of setTimeout
@ -275,7 +280,7 @@ function askForConfig(answers, mainCb) {
function next() { function next() {
var q = nextSet.shift(); var q = nextSet.shift();
if (!q) { rl.close(); mainCb(null, answers); return; } if (!q) { if (useTty) { stdin.close(); } rl.close(); mainCb(null, answers); return; }
q(next); q(next);
} }

View File

@ -319,7 +319,7 @@ if [ "systemd" == "$my_system_launcher" ]; then
$sudo_cmd systemctl restart $my_app $sudo_cmd systemctl restart $my_app
fi fi
echo "telebit init" echo "telebit init --tty"
sleep 2 sleep 2
$TELEBIT_PATH/bin/node $TELEBIT_PATH/bin/telebit.js init $TELEBIT_PATH/bin/node $TELEBIT_PATH/bin/telebit.js init