Define a common helper for prompting to the user consistently

This commit is contained in:
Jérémie Astori 2016-12-16 02:27:41 -05:00
parent 6c546b2098
commit 770ede0587
3 changed files with 8 additions and 7 deletions

View File

@ -15,8 +15,8 @@ program
log.error(`User ${colors.bold(name)} already exists.`); log.error(`User ${colors.bold(name)} already exists.`);
return; return;
} }
require("read")({ log.prompt({
prompt: log.rawInfo("Enter password: "), text: "Enter password:",
silent: true silent: true
}, function(err, password) { }, function(err, password) {
if (!password) { if (!password) {

View File

@ -17,8 +17,8 @@ program
} }
var file = Helper.getUserConfigPath(name); var file = Helper.getUserConfigPath(name);
var user = require(file); var user = require(file);
require("read")({ log.prompt({
prompt: log.rawInfo("Enter new password: "), text: "Enter new password:",
silent: true silent: true
}, function(err, password) { }, function(err, password) {
if (err) { if (err) {

View File

@ -2,6 +2,7 @@
var colors = require("colors/safe"); var colors = require("colors/safe");
var moment = require("moment"); var moment = require("moment");
const read = require("read");
var Helper = require("./helper"); var Helper = require("./helper");
function timestamp(type, messageArgs) { function timestamp(type, messageArgs) {
@ -31,7 +32,7 @@ exports.debug = function() {
console.log.apply(console, timestamp(colors.green("[DEBUG]"), arguments)); console.log.apply(console, timestamp(colors.green("[DEBUG]"), arguments));
}; };
exports.rawInfo = function() { exports.prompt = (options, callback) => {
const newArguments = timestamp(colors.blue("[INFO]"), arguments); options.prompt = timestamp(colors.cyan("[PROMPT]"), [options.text]).join(" ");
return Array.prototype.slice.call(newArguments).join(" "); read(options, callback);
}; };