@@ -211,6 +211,37 @@ Supported keys:
211211 + default: '["[", "]"]' # ✔️ RIGHT
212212 ```
213213
214+ If the default value does not apply to all cases, i.e., an answer is required under
215+ certain conditions, then the default can be unset by rendering the special ` UNSET `
216+ variable to force the user to provide an answer:
217+
218+ !!! example
219+
220+ ```yaml title="copier.yml"
221+ database_engine:
222+ type: str
223+ help: Database engine
224+ choices:
225+ - postgres
226+ - mysql
227+ - other
228+ default: postgres
229+
230+ database_url:
231+ type: str
232+ help: Database URL
233+ default: >-
234+ {%- if database_engine == 'postgres' -%}
235+ postgresql://user:pass@localhost:5432/dbname
236+ {%- elif database_engine == 'mysql' -%}
237+ mysql://user:pass@localhost:3306/dbname
238+ {%- else -%}
239+ {{ UNSET }}
240+ {%- endif -%}
241+ # Simplified for illustration purposes
242+ validator: "{% if '://' not in database_url %}Invalid{% endif %}"
243+ ```
244+
214245- ** secret** : When ` true ` , it hides the prompt displaying asterisks (` ***** ` ) and
215246 doesn't save the answer in [ the answers file] [ the-copier-answersyml-file ] . When
216247 ` true ` , a default value is required.
@@ -282,35 +313,8 @@ Supported keys:
282313
283314 If the default value of a skipped question is not meaningful, then it can be unset
284315 by rendering the special ` UNSET ` variable, so the question's variable is undefined
285- in the render context:
286-
287- !!! example
288-
289- ```yaml title="copier.yml"
290- database_engine:
291- type: str
292- help: Database engine
293- choices:
294- - postgres
295- - mysql
296- - none
297- default: postgres
298-
299- database_url:
300- type: str
301- help: Database URL
302- default: >-
303- {%- if database_engine == 'postgres' -%}
304- postgresql://user:pass@localhost:5432/dbname
305- {%- elif database_engine == 'mysql' -%}
306- mysql://user:pass@localhost:3306/dbname
307- {%- else -%}
308- {{ UNSET }}
309- {%- endif -%}
310- when: "{{ database_engine != 'none' }}"
311- # Simplified for illustration purposes
312- validator: "{% if '://' not in database_url %}Invalid{% endif %}"
313- ```
316+ in the render context. See an example using ` UNSET ` in the section for ` default `
317+ above.
314318
315319!!! example
316320
0 commit comments