mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 13:27:15 +08:00
Add inquirer
This commit is contained in:
528
inquirer/inquirer-tests.ts
Normal file
528
inquirer/inquirer-tests.ts
Normal file
@@ -0,0 +1,528 @@
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
/// <reference path="inquirer.d.ts" />
|
||||
|
||||
import inquirer = require('inquirer');
|
||||
|
||||
|
||||
inquirer.prompt([/* Pass your questions in here */], function( answers: inquirer.Answers ) {
|
||||
// Use user feedback for... whatever!!
|
||||
});
|
||||
|
||||
//
|
||||
// examples/bottom-bar.js
|
||||
//
|
||||
|
||||
//var BottomBar = require("../lib/ui/bottom-bar");
|
||||
var BottomBar = inquirer.ui.BottomBar;
|
||||
declare var cmdify: any;
|
||||
|
||||
var loader = [
|
||||
"/ Installing",
|
||||
"| Installing",
|
||||
"\\ Installing",
|
||||
"- Installing"
|
||||
];
|
||||
var i = 4;
|
||||
var ui = new BottomBar({ bottomBar: loader[i % 4] });
|
||||
|
||||
setInterval(function() {
|
||||
ui.updateBottomBar( loader[i++ % 4] );
|
||||
}, 300 );
|
||||
|
||||
var spawn = require("child_process").spawn;
|
||||
|
||||
var cmd = spawn(cmdify("npm"), [ "-g", "install", "inquirer" ], { stdio: "pipe" });
|
||||
cmd.stdout.pipe( ui.log );
|
||||
cmd.on( "close", function() {
|
||||
ui.updateBottomBar("Installation done!\n");
|
||||
process.exit();
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// examples/checkbox.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Checkbox list examples
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: "checkbox",
|
||||
message: "Select toppings",
|
||||
name: "toppings",
|
||||
choices: [
|
||||
new inquirer.Separator("The usual:"),
|
||||
{
|
||||
name: "Peperonni"
|
||||
},
|
||||
{
|
||||
name: "Cheese",
|
||||
checked: true
|
||||
},
|
||||
{
|
||||
name: "Mushroom"
|
||||
},
|
||||
new inquirer.Separator("The extras:"),
|
||||
{
|
||||
name: "Pineapple",
|
||||
},
|
||||
{
|
||||
name: "Bacon"
|
||||
},
|
||||
{
|
||||
name: "Olives",
|
||||
disabled: "out of stock"
|
||||
},
|
||||
{
|
||||
name: "Extra cheese"
|
||||
}
|
||||
],
|
||||
validate: function( answer ) {
|
||||
if ( answer.length < 1 ) {
|
||||
return "You must choose at least one topping.";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
], function( answers: inquirer.Answers ) {
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// examples/expand.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Expand list examples
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: "expand",
|
||||
message: "Conflict on `file.js`: ",
|
||||
name: "overwrite",
|
||||
choices: [
|
||||
{
|
||||
key: "y",
|
||||
name: "Overwrite",
|
||||
value: "overwrite"
|
||||
},
|
||||
{
|
||||
key: "a",
|
||||
name: "Overwrite this one and all next",
|
||||
value: "overwrite_all"
|
||||
},
|
||||
{
|
||||
key: "d",
|
||||
name: "Show diff",
|
||||
value: "diff"
|
||||
},
|
||||
new inquirer.Separator(),
|
||||
{
|
||||
key: "x",
|
||||
name: "Abort",
|
||||
value: "abort"
|
||||
}
|
||||
]
|
||||
}
|
||||
], function( answers: inquirer.Answers ) {
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// examples/input.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Input prompt example
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
var questions = [
|
||||
{
|
||||
type: "input",
|
||||
name: "first_name",
|
||||
message: "What's your first name"
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
name: "last_name",
|
||||
message: "What's your last name",
|
||||
default: function () { return "Doe"; }
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
name: "phone",
|
||||
message: "What's your phone number",
|
||||
validate: function( value: string ): string|boolean {
|
||||
var pass = value.match(/^([01]{1})?[\-\.\s]?\(?(\d{3})\)?[\-\.\s]?(\d{3})[\-\.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i);
|
||||
if (pass) {
|
||||
return true;
|
||||
} else {
|
||||
return "Please enter a valid phone number";
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
inquirer.prompt( questions, function( answers ) {
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
|
||||
//
|
||||
// examples/list.js
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* List prompt example
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: "list",
|
||||
name: "theme",
|
||||
message: "What do you want to do?",
|
||||
choices: [
|
||||
"Order a pizza",
|
||||
"Make a reservation",
|
||||
new inquirer.Separator(),
|
||||
"Ask opening hours",
|
||||
"Talk to the receptionnist"
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "list",
|
||||
name: "size",
|
||||
message: "What size do you need",
|
||||
choices: [ "Jumbo", "Large", "Standard", "Medium", "Small", "Micro" ],
|
||||
filter: function( val: string ) { return val.toLowerCase(); }
|
||||
}
|
||||
], function( answers: inquirer.Answers ) {
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
|
||||
//
|
||||
// examples/long-list.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Paginated list
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
var choices = Array.apply(0, new Array(26)).map(function(x: number,y: number) {
|
||||
return String.fromCharCode(y + 65);
|
||||
});
|
||||
choices.push("Multiline option \n super cool feature");
|
||||
choices.push("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.");
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type : "list",
|
||||
name : "letter",
|
||||
message : "What's your favorite letter?",
|
||||
paginated : true,
|
||||
choices : choices
|
||||
},
|
||||
{
|
||||
type : "checkbox",
|
||||
name : "name",
|
||||
message : "Select the letter contained in your name:",
|
||||
paginated : true,
|
||||
choices : choices
|
||||
}
|
||||
], function( answers: inquirer.Answers ) {
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
|
||||
//
|
||||
// examples/nested-call.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Nested Inquirer call
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
inquirer.prompt({
|
||||
type: "list",
|
||||
name: "chocolate",
|
||||
message: "What's your favorite chocolate?",
|
||||
choices: [ "Mars", "Oh Henry", "Hershey" ]
|
||||
}, function( answers: inquirer.Answers ) {
|
||||
inquirer.prompt({
|
||||
type: "list",
|
||||
name: "beverage",
|
||||
message: "And your favorite beverage?",
|
||||
choices: [ "Pepsi", "Coke", "7up", "Mountain Dew", "Red Bull" ]
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// examples/password.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Password prompt example
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: "password",
|
||||
message: "Enter your git password",
|
||||
name: "password"
|
||||
}
|
||||
], function( answers: inquirer.Answers ) {
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
|
||||
//
|
||||
// examples/pizza.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Pizza delivery prompt example
|
||||
* run example by writing `node pizza.js` in your console
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
console.log("Hi, welcome to Node Pizza");
|
||||
|
||||
var questions2 = [
|
||||
{
|
||||
type: "confirm",
|
||||
name: "toBeDelivered",
|
||||
message: "Is it for a delivery",
|
||||
default: false
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
name: "phone",
|
||||
message: "What's your phone number",
|
||||
validate: function( value: string ): string|boolean {
|
||||
var pass = value.match(/^([01]{1})?[\-\.\s]?\(?(\d{3})\)?[\-\.\s]?(\d{3})[\-\.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i);
|
||||
if (pass) {
|
||||
return true;
|
||||
} else {
|
||||
return "Please enter a valid phone number";
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "list",
|
||||
name: "size",
|
||||
message: "What size do you need",
|
||||
choices: [ "Large", "Medium", "Small" ],
|
||||
filter: function( val: string ) { return val.toLowerCase(); }
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
name: "quantity",
|
||||
message: "How many do you need",
|
||||
validate: function( value: string ) {
|
||||
var valid = !isNaN(parseFloat(value));
|
||||
return valid || "Please enter a number";
|
||||
},
|
||||
filter: Number
|
||||
},
|
||||
{
|
||||
type: "expand",
|
||||
name: "toppings",
|
||||
message: "What about the toping",
|
||||
choices: [
|
||||
{
|
||||
key: "p",
|
||||
name: "Peperonni and chesse",
|
||||
value: "PeperonniChesse"
|
||||
},
|
||||
{
|
||||
key: "a",
|
||||
name: "All dressed",
|
||||
value: "alldressed"
|
||||
},
|
||||
{
|
||||
key: "w",
|
||||
name: "Hawaïan",
|
||||
value: "hawaian"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "rawlist",
|
||||
name: "beverage",
|
||||
message: "You also get a free 2L beverage",
|
||||
choices: [ "Pepsi", "7up", "Coke" ]
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
name: "comments",
|
||||
message: "Any comments on your purchase experience",
|
||||
default: "Nope, all good!"
|
||||
},
|
||||
{
|
||||
type: "list",
|
||||
name: "prize",
|
||||
message: "For leaving a comments, you get a freebie",
|
||||
choices: [ "cake", "fries" ],
|
||||
when: function( answers: inquirer.Answers ) {
|
||||
return answers['comments'] !== "Nope, all good!";
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
inquirer.prompt( questions, function( answers ) {
|
||||
console.log("\nOrder receipt:");
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
|
||||
//
|
||||
// examples/rawlist.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Raw List prompt example
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: "rawlist",
|
||||
name: "theme",
|
||||
message: "What do you want to do?",
|
||||
choices: [
|
||||
"Order a pizza",
|
||||
"Make a reservation",
|
||||
new inquirer.Separator(),
|
||||
"Ask opening hours",
|
||||
"Talk to the receptionnist"
|
||||
]
|
||||
},
|
||||
{
|
||||
type: "rawlist",
|
||||
name: "size",
|
||||
message: "What size do you need",
|
||||
choices: [ "Jumbo", "Large", "Standard", "Medium", "Small", "Micro" ],
|
||||
filter: function( val: string ) { return val.toLowerCase(); }
|
||||
}
|
||||
], function( answers: inquirer.Answers ) {
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
|
||||
//
|
||||
// examples/recursive.js
|
||||
//
|
||||
|
||||
/**
|
||||
* Recursive prompt example
|
||||
* Allows user to choose when to exit prompt
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
var output2: (string|boolean)[] = [];
|
||||
|
||||
var questions3 = [
|
||||
{
|
||||
type: "input",
|
||||
name: "tvShow",
|
||||
message: "What's your favorite TV show?"
|
||||
},
|
||||
{
|
||||
type: "confirm",
|
||||
name: "askAgain",
|
||||
message: "Want to enter another TV show favorite (just hit enter for YES)?",
|
||||
default: true
|
||||
}
|
||||
];
|
||||
|
||||
function ask() {
|
||||
inquirer.prompt( questions3, function( answers: inquirer.Answers ) {
|
||||
output2.push( answers['tvShow'] );
|
||||
if ( answers['askAgain'] ) {
|
||||
ask();
|
||||
} else {
|
||||
console.log( "Your favorite TV Shows:", output2.join(", ") );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ask();
|
||||
|
||||
//
|
||||
// examples/when.js
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* When example
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//var inquirer = require("../lib/inquirer");
|
||||
|
||||
var questions4 = [
|
||||
{
|
||||
type: "confirm",
|
||||
name: "bacon",
|
||||
message: "Do you like bacon?"
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
name: "favorite",
|
||||
message: "Bacon lover, what is your favorite type of bacon?",
|
||||
when: function ( answers: inquirer.Answers ) {
|
||||
return answers['bacon'];
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "confirm",
|
||||
name: "pizza",
|
||||
message: "Ok... Do you like pizza?",
|
||||
when: function (answers: inquirer.Answers) {
|
||||
return !likesFood( "bacon" )(answers);
|
||||
}
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
name: "favorite",
|
||||
message: "Whew! What is your favorite type of pizza?",
|
||||
when: likesFood( "pizza" )
|
||||
}
|
||||
];
|
||||
|
||||
function likesFood ( aFood: string ) {
|
||||
return function ( answers: inquirer.Answers ) {
|
||||
return answers[ aFood ];
|
||||
}
|
||||
}
|
||||
|
||||
inquirer.prompt(questions, function (answers) {
|
||||
console.log( JSON.stringify(answers, null, " ") );
|
||||
});
|
||||
299
inquirer/inquirer.d.ts
vendored
Normal file
299
inquirer/inquirer.d.ts
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
// Type definitions for Inquirer.js
|
||||
// Project: https://github.com/SBoudrias/Inquirer.js
|
||||
// Definitions by: Qubo <https://github.com/tkQubo>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../rx/rx-lite.d.ts" />
|
||||
/// <reference path="../through/through.d.ts" />
|
||||
|
||||
declare module "inquirer" {
|
||||
import through = require('through');
|
||||
|
||||
namespace inquirer {
|
||||
type Prompts = { [name: string]: PromptModule };
|
||||
type ChoiceType = string|objects.ChoiceOption|objects.Separator;
|
||||
type Questions = Question|Question[]|Rx.Observable<Question>;
|
||||
|
||||
interface Inquirer {
|
||||
restoreDefaultPrompts(): void;
|
||||
/**
|
||||
* Expose helper functions on the top level for easiest usage by common users
|
||||
* @param name
|
||||
* @param prompt
|
||||
*/
|
||||
registerPrompt(name: string, prompt: PromptModule): void;
|
||||
/**
|
||||
* Create a new self-contained prompt module.
|
||||
*/
|
||||
createPromptModule(): PromptModule;
|
||||
/**
|
||||
* Public CLI helper interface
|
||||
* @param questions Questions settings array
|
||||
* @param cb Callback being passed the user answers
|
||||
* @return
|
||||
*/
|
||||
prompt(questions: Questions, cb?: (answers: Answers) => any): ui.Prompt;
|
||||
prompts: Prompts;
|
||||
Separator: objects.SeparatorStatic;
|
||||
ui: {
|
||||
BottomBar: ui.BottomBar;
|
||||
Prompt: ui.Prompt;
|
||||
}
|
||||
}
|
||||
|
||||
interface PromptModule {
|
||||
(questions: Questions, cb: (answers: Answers) => any): ui.Prompt;
|
||||
/**
|
||||
* Register a prompt type
|
||||
* @param name Prompt type name
|
||||
* @param prompt Prompt constructor
|
||||
*/
|
||||
registerPrompt(name: string, prompt: PromptModule): ui.Prompt;
|
||||
/**
|
||||
* Register the defaults provider prompts
|
||||
*/
|
||||
restoreDefaultPrompts(): void;
|
||||
}
|
||||
|
||||
interface Question {
|
||||
/**
|
||||
* Type of the prompt.
|
||||
* Possible values:
|
||||
* <ul>
|
||||
* <li>input</li>
|
||||
* <li>confirm</li>
|
||||
* <li>list</li>
|
||||
* <li>rawlist</li>
|
||||
* <li>password</li>
|
||||
* </ul>
|
||||
* @defaults: 'input'
|
||||
*/
|
||||
type?: string;
|
||||
/**
|
||||
* The name to use when storing the answer in the anwers hash.
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* The question to print. If defined as a function,
|
||||
* the first parameter will be the current inquirer session answers.
|
||||
*/
|
||||
message?: string|((answers: Answers) => string);
|
||||
/**
|
||||
* Default value(s) to use if nothing is entered, or a function that returns the default value(s).
|
||||
* If defined as a function, the first parameter will be the current inquirer session answers.
|
||||
*/
|
||||
default?: any|((answers: Answers) => any);
|
||||
/**
|
||||
* Choices array or a function returning a choices array. If defined as a function,
|
||||
* the first parameter will be the current inquirer session answers.
|
||||
* Array values can be simple strings, or objects containing a name (to display) and a value properties
|
||||
* (to save in the answers hash). Values can also be a Separator.
|
||||
*/
|
||||
choices?: ChoiceType[]|((answers: Answers) => ChoiceType[]);
|
||||
/**
|
||||
* Receive the user input and should return true if the value is valid, and an error message (String)
|
||||
* otherwise. If false is returned, a default error message is provided.
|
||||
*/
|
||||
validate?(input: string): boolean|string;
|
||||
/**
|
||||
* Receive the user input and return the filtered value to be used inside the program.
|
||||
* The value returned will be added to the Answers hash.
|
||||
*/
|
||||
filter?(input: string): string;
|
||||
/**
|
||||
* Receive the current user answers hash and should return true or false depending on whether or
|
||||
* not this question should be asked. The value can also be a simple boolean.
|
||||
*/
|
||||
when?: boolean|((answers: Answers) => boolean);
|
||||
paginated?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A key/value hash containing the client answers in each prompt.
|
||||
*/
|
||||
interface Answers {
|
||||
[key: string]: string|boolean;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
/**
|
||||
* Base interface class other can inherits from
|
||||
*/
|
||||
interface Prompt extends BaseUI<Prompts> {
|
||||
new(promptModule: Prompts): Prompt;
|
||||
/**
|
||||
* Once all prompt are over
|
||||
*/
|
||||
onCompletion(): void;
|
||||
processQuestion(question: Question): any;
|
||||
fetchAnswer(question: Question): any;
|
||||
setDefaultType(question: Question): any;
|
||||
filterIfRunnable(question: Question): any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sticky bottom bar user interface
|
||||
*/
|
||||
interface BottomBar extends BaseUI<BottomBarOption> {
|
||||
new(opt?: BottomBarOption): BottomBar;
|
||||
/**
|
||||
* Render the prompt to screen
|
||||
* @return self
|
||||
*/
|
||||
render(): BottomBar;
|
||||
/**
|
||||
* Update the bottom bar content and rerender
|
||||
* @param bottomBar Bottom bar content
|
||||
* @return self
|
||||
*/
|
||||
updateBottomBar(bottomBar: string): BottomBar;
|
||||
/**
|
||||
* Rerender the prompt
|
||||
* @return self
|
||||
*/
|
||||
writeLog(data: any): BottomBar;
|
||||
/**
|
||||
* Make sure line end on a line feed
|
||||
* @param str Input string
|
||||
* @return The input string with a final line feed
|
||||
*/
|
||||
enforceLF(str: string): string;
|
||||
/**
|
||||
* Helper for writing message in Prompt
|
||||
* @param message The message to be output
|
||||
*/
|
||||
write(message: string): void;
|
||||
log: through.ThroughStream;
|
||||
}
|
||||
|
||||
interface BottomBarOption {
|
||||
bottomBar?: string;
|
||||
}
|
||||
/**
|
||||
* Base interface class other can inherits from
|
||||
*/
|
||||
interface BaseUI<TOpt> {
|
||||
new(opt: TOpt): void;
|
||||
/**
|
||||
* Handle the ^C exit
|
||||
* @return {null}
|
||||
*/
|
||||
onForceClose(): void;
|
||||
/**
|
||||
* Close the interface and cleanup listeners
|
||||
*/
|
||||
close(): void;
|
||||
/**
|
||||
* Handle and propagate keypress events
|
||||
*/
|
||||
onKeypress(s: string, key: Key): void;
|
||||
}
|
||||
|
||||
interface Key {
|
||||
sequence: string;
|
||||
name: string;
|
||||
meta: boolean;
|
||||
shift: boolean;
|
||||
ctrl: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
namespace objects {
|
||||
/**
|
||||
* Choice object
|
||||
* Normalize input as choice object
|
||||
* @constructor
|
||||
* @param {String|Object} val Choice value. If an object is passed, it should contains
|
||||
* at least one of `value` or `name` property
|
||||
*/
|
||||
interface Choice {
|
||||
new(str: string): Choice;
|
||||
new(separator: Separator): Choice;
|
||||
new(option: ChoiceOption): Choice;
|
||||
}
|
||||
|
||||
interface ChoiceOption {
|
||||
name?: string;
|
||||
value?: string;
|
||||
type?: string;
|
||||
extra?: any;
|
||||
key?: string;
|
||||
checked?: boolean;
|
||||
disabled?: string|((answers: Answers) => any);
|
||||
}
|
||||
|
||||
/**
|
||||
* Choices collection
|
||||
* Collection of multiple `choice` object
|
||||
* @constructor
|
||||
* @param choices All `choice` to keep in the collection
|
||||
*/
|
||||
interface Choices {
|
||||
new(choices: (string|Separator|ChoiceOption)[], answers?: Answers): Choices;
|
||||
choices: Choice[];
|
||||
realChoices: Choice[];
|
||||
length: number;
|
||||
realLength: number;
|
||||
/**
|
||||
* Get a valid choice from the collection
|
||||
* @param selector The selected choice index
|
||||
* @return Return the matched choice or undefined
|
||||
*/
|
||||
getChoice(selector: number): Choice;
|
||||
/**
|
||||
* Get a raw element from the collection
|
||||
* @param selector The selected index value
|
||||
* @return Return the matched choice or undefined
|
||||
*/
|
||||
get(selector: number): Choice;
|
||||
/**
|
||||
* Match the valid choices against a where clause
|
||||
* @param whereClause Lodash `where` clause
|
||||
* @return Matching choices or empty array
|
||||
*/
|
||||
where<U extends {}>(whereClause: U): Choice[];
|
||||
/**
|
||||
* Pluck a particular key from the choices
|
||||
* @param propertyName Property name to select
|
||||
* @return Selected properties
|
||||
*/
|
||||
pluck(propertyName: string): any[];
|
||||
forEach<T>(application: (choice: Choice) => T): T[];
|
||||
}
|
||||
|
||||
interface SeparatorStatic {
|
||||
/**
|
||||
* @param line Separation line content (facultative)
|
||||
*/
|
||||
new(line?: string): Separator;
|
||||
/**
|
||||
* Helper function returning false if object is a separator
|
||||
* @param obj object to test against
|
||||
* @return `false` if object is a separator
|
||||
*/
|
||||
exclude(obj: any): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Separator object
|
||||
* Used to space/separate choices group
|
||||
* @constructor
|
||||
* @param {String} line Separation line content (facultative)
|
||||
*/
|
||||
interface Separator {
|
||||
type: string;
|
||||
line: string;
|
||||
/**
|
||||
* Stringify separator
|
||||
* @return {String} the separator display string
|
||||
*/
|
||||
toString(): string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var inquirer: inquirer.Inquirer;
|
||||
|
||||
export = inquirer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user