-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from arlando/feature-when-example
Added an example using when.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* When example | ||
*/ | ||
|
||
"use strict"; | ||
var inquirer = require("../lib/inquirer"); | ||
|
||
var questions = [ | ||
{ | ||
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 ) { | ||
return answers.bacon; | ||
} | ||
}, | ||
{ | ||
type: "confirm", | ||
name: "pizza", | ||
message: "Ok... Do you like pizza?", | ||
when: function (answers) { | ||
return !likesFood( "bacon" )(answers); | ||
} | ||
}, | ||
{ | ||
type: "input", | ||
name: "favorite", | ||
message: "Whew! What is your favorite type of pizza?", | ||
when: likesFood( "pizza" ) | ||
} | ||
]; | ||
|
||
function likesFood ( aFood ) { | ||
return function ( answers ) { | ||
return answers[ aFood ]; | ||
} | ||
} | ||
|
||
inquirer.prompt(questions, function (answers) { | ||
console.log( JSON.stringify(answers, null, " ") ); | ||
}); |