Skip to content
Myr

Added `Commander#confirm()`

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 e7cdf10 · Browse files · 2 files+22 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

2 files+22 added−0 removed

  • other:+22 added−0 removed

2 files+22 added−0 removed

added:examples/confirm+12 added
1#!/usr/bin/env node23/**4 * Module dependencies.5 */67var program = require('../');89program.confirm('continue? ', function(ok){10 console.log(' got %j', ok);11 process.stdin.destroy();12});
modified:lib/commander.js+10 added
376 unmodified lines
377 if (/ $/.test(str)) return this.promptSingleLine.apply(this, arguments);378 this.promptMultiLine(str, fn);379};380381Command.prototype.confirm = function(str, fn){382 this.prompt(str, function(ok){383 fn(parseBool(ok));384 });385};386387Command.prototype.choose = function(list, fn){388 var self = this;389390 list.forEach(function(item, i){
13 unmodified lines
404405 again();406};407408function parseBool(str) {409 return /^y|yes|ok|true$/i.test(str);410}411412function pad(str, width) {413 var len = Math.max(0, width - str.length);414 return str + Array(len + 1).join(' ');415}