SBoudrias/Inquirer.js

Pseudo-prompt to always perform a task

jftanner opened this issue · 5 comments

I'm not sure if this is a feature request or just request for advice. If this is already possible, I'm very open to suggestions of how to do it.

Here's my the flow I'm looking for:
0. Load answers from command line or env

  1. Prompt for username (If not already provided)
  2. Prompt for password (If not already provided)
  3. Initialize some client
  4. Load some information via the client
  5. Prompt with question about that information (If not already provided)
  6. Repeat 4 and 5 until done

The questions that need to use the client all do so via an async choices function, which works quite well. But the problem I'm having is finding an elegant way to initialize the client inside the questions flow. I can't put it as a filter in the password, because then it's not generated if the password is pre-answered. And if I put it inside the choices of the first question, then that means that question can't be pre-answered. And either way, it feels "hacky", since the client is being set up inside an otherwise-unrelated question.

What I think I need is some kind of prompt that doesn't actually ask the user a question, but instead adds a new answer based on information already provided. That way, there's a question specifically to generate the client and nothing else.

Any ideas would be greatly appreciated.

Hi, I think you're trying to do too much with Inquirer. Instead, you could just use JavaScript.

It might be worthwhile looking into the new API #1214, it is simplified and might simplify how you approach the control flow.

Ooh. Is the idea that you prompt for individual questions as you need them, rather than a whole array at once?
That would absolutely streamline my process flow.

Ooh. Is the idea that you prompt for individual questions as you need them, rather than a whole array at once?

That's right 😄

Perfect! That's vastly better than what I'm doing now. I'll switch over to that and give it a try.

The new approach is fantastic. My code is much, much cleaner now. Thank you!

The only issue I ran into was #1283, and that's small enough that I'll continue with the conversion.

Thanks again!