Code Monkey home page Code Monkey logo

Comments (4)

SBoudrias avatar SBoudrias commented on May 21, 2024

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.

CDHDeveloper avatar CDHDeveloper commented on May 21, 2024

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.

SBoudrias avatar SBoudrias commented on May 21, 2024

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.

dgrcode avatar dgrcode commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.