magmax / python-inquirer

A collection of common interactive command line user interfaces, based on Inquirer.js (https://github.com/SBoudrias/Inquirer.js/)
MIT License
996 stars 98 forks source link

Ability to override questions defaults #14

Closed lelit closed 5 years ago

lelit commented 8 years ago

Maybe I'm missing something, but I was not able to pass an set of pre answers to the prompt() function, to override the default values of the questions.

My use case is double:

  1. I'd like to implement a way to load predefined defaults from a file, before prompting the user
  2. An application I wrote (tinject) has a cascade of prompts, where any question may be repeated: at the second prompt() I'd like to be presented the answer given in the first, if any

At first I tried to use the answers argument to the prompt() function, but it didn't have any effect, and checking the source seems to confirm that.

In lelit@8480308fb09990f5dfe7f2214edf12923e6dd900 I modified the default property of the Question class to return the answered value, if present. Does that sound reasonable, or is there a better way to accomplish my goal?

magmax commented 8 years ago

Sounds reasonable and I like it. Could you please send the pull-request? I will publish it as soon as possible, but I'm very busy right now.

lelit commented 8 years ago

Great, I'll do a PR, thank you!