copier
copier copied to clipboard
Add support for multiple prompts of the same type
Is your feature request related to a problem? Please describe.
I'd like to prompt for zero or more additional dependencies (package names + optional version specifiers, e.g. cowsay or cowsay@>=5.0) to be included in the dependency specification of a generated Python project. Currently, there is no way of repeating a prompt and appending the answers to a list.
Describe the solution you'd like I imagine a solution could look like this:
dependencies:
type: str
help: Additional dependencies
multiple:
help: Add another dependency?
min: 0
The multiple field could have the following variants:
multiple: true # uses defaults for all fields
multiple:
help: <str> # optional, defaults to "More?"
min: <nonnegative int> # optional, defaults to 0
max: <positive int> # optional, defaults to ∞
A type: bool question specified by multiple.help would be asked before accepting the input for any optional item and deleted again from the terminal when answered. For instance, when min: 2 then the confirm question would be asked only after 2 inputs, and when max: 4 then the questionnaire would proceed to the next question after the fourth answer had been provided. The answers would be gathered in a list. The validation expression, when present, would be executed after every input with the current list of answers. For validating each item independently, only the last item of the list would be accessed in the validation expression. But complex validation logic that depends on previously entered answers or the number of answers so far would be possible, too.
Regarding UX, perhaps the nesting could be visualized using Unicode art similar to how the tree tool prints filesystem trees:
🎤 Additional dependencies
├─ cowsay@>=5.0
└─ requests
The implementation could take some inspiration from https://github.com/RhetTbull/questionary-superprompt#multiple-option.
Describe alternatives you've considered
Alternatively, a type: yaml or type: json prompt could be used, but the flow would not be guided, so the UX would be worse. Also, validation logic would be more complex.
Additional context I'd be happy to work on a PR if this proposal gets accepted.
The field multiple could also be named many instead, inspired by marshmallow's attribute for declaring collections.
Thanks for your contributions! It seems to me that #751 is a more complete proposal that would render this one unnecessary, so let me close here and continue there.
Ah forget the last message, I just understood why these 2 are separate feature requests 🤦🏼♂️
I see this feature could be much helpful, and the design you proposed fits very well with the rest of Copier. I don't plan on developing this, but I'd be glad to review and merge your PR. Indeed, combined with #751 would take Copier forms to the next level!
The field
multiplecould also be namedmanyinstead
I like multiple more.