copier-org / copier

Library and command-line utility for rendering projects templates.
https://readthedocs.org/projects/copier/
MIT License
1.92k stars 173 forks source link

Support dynamic choices #1746

Open jaecktec opened 3 weeks ago

jaecktec commented 3 weeks ago

Actual Situation

I'd like to ask for some choices (my case aws-regions) and in the second step I want that the user selects the primary region from the previously specified region.

Sadly the choices field is not evaluated as expression

Desired Situation

What happens right now: the String is destructed as an array and I can chose a letter from my expression

What should happen: The user should have a way how to dynamicly specify the choices

Proposed solution

I'd like that this works:

list_input:
  type: str
  help: "Enter a comma-separated list of items."
  default: "item1,item2,item3"

selected_choice:
  type: str
  help: "Select one of the items from your list."
  choices: "{{ list_input.split(',') | map('trim') | list }}"
sisp commented 3 weeks ago

The request for dynamic choices has come up a few times. We have a design proposal that looks promising. Would you happen to be interested in attempting an implementation?

jaecktec commented 3 weeks ago

the design proposal is coincidentially the same as my proposal :D

I most likely won't find the time the next months, however if nobody has attempted a PR I'll look into it

sisp commented 3 weeks ago

the design proposal is coincidentially the same as my proposal :D

Ah, yes, of course, I had a Jinja for-loop with explicit YAML list syntax in mind, but you're right. :+1: