From 753da7fa44bb91f27986bbca251a44a364f75c85 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 13 Jun 2018 10:45:54 -0600 Subject: [PATCH] use /dev/tty for stdin when specified --- bin/telebit.js | 27 ++++++++++++++++----------- usr/share/install_helper.sh | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bin/telebit.js b/bin/telebit.js index 164df7e..ee925a7 100644 --- a/bin/telebit.js +++ b/bin/telebit.js @@ -16,15 +16,18 @@ var common = require('../lib/cli-common.js'); var argv = process.argv.slice(2); -var confIndex = argv.indexOf('--config'); +var argIndex = argv.indexOf('--config'); var confpath; -var confargs; -if (-1 === confIndex) { - confIndex = argv.indexOf('-c'); +var useTty; +if (-1 === argIndex) { + argIndex = argv.indexOf('-c'); } -if (-1 !== confIndex) { - confargs = argv.splice(confIndex, 2); - confpath = confargs[1]; +if (-1 !== argIndex) { + confpath = argv.splice(argIndex, 2)[1]; +} +argIndex = argv.indexOf('--tty'); +if (-1 !== argIndex) { + useTty = argv.splice(argIndex, 1); } function help() { @@ -69,7 +72,7 @@ function help() { } var verstr = '' + pkg.name + ' v' + pkg.version; -if (-1 === confIndex) { +if (!confpath) { confpath = path.join(require('os').homedir(), '.config/telebit/telebit.yml'); verstr += ' (--config "' + confpath + '")'; } @@ -87,10 +90,12 @@ if (!confpath || /^--/.test(confpath)) { function askForConfig(answers, mainCb) { answers = answers || {}; //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 rl = readline.createInterface({ - input: process.stdin, - output: process.stdout + input: stdin + , output: process.stdout }); // NOTE: Use of setTimeout @@ -275,7 +280,7 @@ function askForConfig(answers, mainCb) { function next() { 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); } diff --git a/usr/share/install_helper.sh b/usr/share/install_helper.sh index 8a4fba1..ed35de3 100644 --- a/usr/share/install_helper.sh +++ b/usr/share/install_helper.sh @@ -319,7 +319,7 @@ if [ "systemd" == "$my_system_launcher" ]; then $sudo_cmd systemctl restart $my_app fi -echo "telebit init" +echo "telebit init --tty" sleep 2 $TELEBIT_PATH/bin/node $TELEBIT_PATH/bin/telebit.js init