Skip to content
Myr

docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 981fc9e · Browse files · 1 file+42 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+42 added−0 removed

  • other:+42 added−0 removed

1 file+42 added−0 removed

modified:lib/commander.js+42 added
666 unmodified lines
667 }668 }).resume();669};670671/**672 * Prompt `str` and callback `fn(val)`673 *674 * @param {String} str675 * @param {Function} fn676 * @api public677 */678679Command.prototype.prompt = function(str, fn){680 if (/ $/.test(str)) return this.promptSingleLine.apply(this, arguments);681 this.promptMultiLine(str, fn);682};683684/**685 * Confirmation prompt with `str` and callback `fn(bool)`686 *687 * @param {String} str688 * @param {Function} fn689 * @api public690 */691692693Command.prototype.confirm = function(str, fn){694 this.prompt(str, function(ok){695 fn(parseBool(ok));696 });697};698699/**700 * Choice prompt with `list` of items and callback `fn(index, item)`701 *702 * @param {Array} list703 * @param {Function} fn704 * @api public705 */706707Command.prototype.choose = function(list, fn){708 var self = this;709710 list.forEach(function(item, i){
13 unmodified lines
724725 again();726};727728/**729 * Parse a boolean `str`.730 *731 * @param {String} str732 * @return {Boolean}733 * @api private734 */735736function parseBool(str) {737 return /^y|yes|ok|true$/i.test(str);738}739740/**741 * Pad `str` to `width`.742 *743 * @param {String} str744 * @param {Number} width745 * @return {String}746 * @api private747 */748749function pad(str, width) {750 var len = Math.max(0, width - str.length);751 return str + Array(len + 1).join(' ');752}