Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt() doesn't accept a dict of existing answers #40

Open
irons opened this issue Feb 6, 2022 · 2 comments
Open

prompt() doesn't accept a dict of existing answers #40

irons opened this issue Feb 6, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@irons
Copy link

irons commented Feb 6, 2022

In PyInquirer, I'm benefiting from the ability to pass the same dict into prompt() that gets returned:

answers = prompt(questions, answers)

This lets me seed initial defaults from CLI options, and operate successive groups of questions that can reference past answers. Here's the PyInquirer implementation. I don't see anything comparable for InquirerPy (looking here), so I'm merging my own dicts between prompt invocations. Which seems surprisingly fiddly in python until one can require 3.9.

Thanks for your time.

@kazhala
Copy link
Owner

kazhala commented Feb 6, 2022

Hi @irons

You are correct, at the moment this feature does not exist, however looks like it's quite a straightforward feature and reasonable use-case. I can look into including it in the next release.

The only concern or edge case I can think about at the moment is what if the provided answer is using the "index" as the key (question without "name") in the answer dictionary. Do you always explicitly define the name of each question, what do you think would be appropriate when let's say the name of the question is the same (perhaps simply override it)?

# answer of first batch of questions
answers = {
    "question1": True
}

# second batch of questions
answers = prompt([{"name": "question1", "type": "input", "message": "Name:"}], answers=answers)

Thanks,
Kevin

@kazhala kazhala added the enhancement New feature or request label Feb 6, 2022
@irons
Copy link
Author

irons commented Feb 6, 2022

Thanks. I do define question names consistently, because I nearly always ask more than one question at a time, so the names are how I get the answers out — until I tried it just now, I didn't know it would generate indexes in lieu of names.

If I re-use a name in a subsequent question, clobbering the existing value would be the outcome I'd expect, just as if I'd used the same name twice in a single block of questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants