1、getChar
var query=require('cli-interact').getChar;
var answer = query('Tell me one of', 'abcdef');
console.log('you answered:', answer);
2、getChoiceByChar
var query=require('cli-interact').getChoiceByChar;
var answer=query('frequency', ['daily', 'weekly', 'monthly']);
console.log('you answered:', answer);
2018-05-05 14-15-59屏幕截图.png
3、getInteger
var query=require('cli-interact').getNumber;
var answer = query('Give me an int', true); // restrict to integer
console.log('you answered:', answer);
console.log('the typeof of that is:', typeof answer);
2018-05-05 14-19-28屏幕截图.png
4、getIPversion
var query=require('cli-interact').getIPversion;
var answer = query(false);
console.log('you answered:', answer);
answer = query(true);
console.log('you answered:', answer);
5、getNumber
var query=require('cli-interact').getNumber;
var answer = query('Case 1: You MAY give me a number: ', {
allowNoAnswer : true
});
if (answer !== '') {
console.log('No answer.');
} else {
console.log('Thank you for: ', answer);
}
console.log();
answer = query('Case 2: You MUST give me a number: ');
console.log('you answered:', answer);
console.log('the typeof of that is:', typeof answer);
console.log();
answer = query('Case 3: You MUST give me an integer: ', true);
console.log('Thank you for: ', answer);
console.log();
answer = query('Case 4: You MAY give me an answer. If you do, it MUST be an integer', {
allowNoAnswer : true
, requireInteger : true
});
if (answer !== '') {
console.log('No answer.');
} else {
console.log('Thank you for: ', answer);
}
}
2018-05-05 14-44-55屏幕截图.png
6、getYesNo
var query=require('cli-interact').getYesNo;
var answer = query('Is it true');
console.log('you answered:', answer);
7、getYesNoNone
var query=require('cli-interact').getYesNo;
var answer = query('Is it true', true);
if (answer === undefined) {
console.log('you did not answer.');
} else {
console.log('you answered:', answer);
}
}
2018-05-05 14-52-44屏幕截图.png
8、 question
var query=require('cli-interact').question;
var answer = query('Tell me what do you want: ');
console.log('you answered:', answer);
网友评论