Comments (4)
Hi, Inquirer prompt offer such a possibility through the when
function. https://github.com/SBoudrias/Inquirer.js#question
For example:
inquirer.prompt([{
name: "food",
type: "list",
message: "What do you want",
choices: [ "Calzone", "Pizza", "Sub" ]
}, {
name: "toppings",
type: "list",
when: function( answers ) {
// Only run if user answered Pizza to the first prompt
return answers.food === "Pizza";
},
// etc
}]);
Does it work for your use case?
from inquirer.js.
Choosing Calzone (or Pizza or Sub) returns exception generated from base.js:83
throw new Error("You must provide a " + name + "
parameter");
So based on that no.
For the use case as far as I see it, you want to be able to dog leg to another set of questions (like asking what you want on your calzone) then go back to asking any further questions. So really what is needed (thinking out loud) is a way to diverge to another question set and come back. Also you need to be able to specify those other questions in a reasonably easy to maintain manner. You have the "when" but what about the "then", is what I guess I'm saying.
from inquirer.js.
That's because I haven't feed every required field in my example (so I put // etc...
to be filled with your logic).
I see what you mean, but this is 100% possible with the current when
implementation. It may not feel like the cleanest way to you, but it helps maintaining long prompt array without entering a nested hell. Plus, it keeps the Inquirer API surface minimal (easier to read and understand).
Try it out with when
, it'll work out. If you need help down the road, just wave an arm over here and I'll be happy to land a hand (You may also find me on #yeoman on IRC under the pseudo sboudrias).
from inquirer.js.
I think this should be in the documentation. I've also found a separate issue opened for this purpose #1081
from inquirer.js.
Related Issues (20)
- Feature request: Support for "done" callback for all prompt types HOT 4
- Preload input with suggestive text, allow the user to edit. HOT 3
- Feature request: Native filter API for select HOT 1
- Checkbox instructions disappears on space selection HOT 2
- The dist files for CommonJS are not correct HOT 2
- Downgrade or use multi-version for those pure ESM packages HOT 6
- Cannot find package '@inquirer/prompts' HOT 3
- Checkbox default selection HOT 3
- Does `select` in @inquirer/prompts support separators? HOT 5
- Allow prompts to keep their current content on validation error HOT 3
- Remove unused dependencies HOT 1
- Package is wrongly configured for TS Node16 resolver
- CLI cursor missing after force quit
- inquirer/confirm accepts more than just 'Y' and 'n' answers. HOT 3
- Typescript build issues HOT 7
- Error in transformer when using default exits silently (version 8)
- How do I force a re-render from inside the context of createPrompt? HOT 2
- Combine multiple state updates into a single operation to reduce renders HOT 2
- State system should not force a render when the new value is the same as the previous value
- A declaration file cannoty be imported without 'import type'. Did you mean to import an implementation file instead? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inquirer.js.