A library for creating command-line interfaces and harvesting information from them.
npm install minimal-prompt --save
Used to prompt the user with a specific set of questions and get their answers to each one.
Arguments
-
questions
(array): The set of questions to prompt the user with. -
options
(object): An object describing the behavior of the prompt.
Options
-
prompt
(string): A string to begin each input line with. -
delimiter
(string): A string to separate the prompt from the user input. -
onComplete
(function): The function invoked when all questions are complete. -
formatPrompt
(function): A function to format the prompt.-
formatPrompt(prompt, delimiter, name)
-
prompt
(string): The specified prompt string. -
delimiter
(string): The specified delimter string. -
name
(string): If using aquestion
prompt, the question being asked. (Only available for a question prompt)
-
-
Example
var prompt = require('minimal-prompt');
prompt.question(['First Name', 'Last Name'], {
prompt: '>',
delimiter: ':',
formatPrompt: function(prompt, delim, name) {
// Note: this is the default prompt for the question option.
return prompt + delim + ' ' + name + delim + ' ';
},
onComplete: function(results) {
console.log('First name:', results.firstName);
console.log('Last name:', results.lastName);
}
});
// prompt.start() will begin the prompting process.
prompt.start();
Used to repeatedly prompt the user for information using the same prompt.
Arguments
-
options
(object): An object describing the behavior of the prompt.
Options
-
prompt
(string): A string to begin each input line with. -
delimiter
(string): A string to separate the prompt from the user input. -
onLine
(function): The function invoked when a new line of input is ready. -
formatPrompt
(function): A function to format the prompt.-
formatPrompt(prompt, delimiter)
-
prompt
(string): The specified prompt string. -
delimiter
(string): The specified delimter string.
-
-
Example
var prompt = require('minimal-prompt');
prompt.repeat({
prompt: '>',
delimiter: ':',
formatPrompt: function(prompt, delim, name) {
// Note: this is the default prompt for the repeat option.
return prompt + delim + ' ';
},
onLine: function(results) {
console.log('Response:', res);
}
});
// prompt.start() will begin the prompting process.
prompt.start();