Skip to content

Commit 00e51bd

Browse files
authored
feat: add support for pre-update and post-update messages (#1288)
* feat: add support for pre-update and post-update messages * test: use verbose regex syntax
1 parent c5cfd57 commit 00e51bd

File tree

4 files changed

+273
-35
lines changed

4 files changed

+273
-35
lines changed

copier/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,14 @@ def run_update(self) -> None:
805805
# review the diff before committing; so we can safely avoid
806806
# asking for confirmation
807807
raise UserMessageError("Enable overwrite to update a subproject.")
808+
self._print_message(self.template.message_before_update)
808809
if not self.quiet:
809810
# TODO Unify printing tools
810811
print(
811812
f"Updating to template version {self.template.version}", file=sys.stderr
812813
)
813814
self._apply_update()
815+
self._print_message(self.template.message_after_update)
814816

815817
def _apply_update(self):
816818
subproject_top = Path(

copier/template.py

+10
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,21 @@ def message_after_copy(self) -> str:
309309
"""Get message to print after copy action specified in the template."""
310310
return self.config_data.get("message_after_copy", "")
311311

312+
@cached_property
313+
def message_after_update(self) -> str:
314+
"""Get message to print after update action specified in the template."""
315+
return self.config_data.get("message_after_update", "")
316+
312317
@cached_property
313318
def message_before_copy(self) -> str:
314319
"""Get message to print before copy action specified in the template."""
315320
return self.config_data.get("message_before_copy", "")
316321

322+
@cached_property
323+
def message_before_update(self) -> str:
324+
"""Get message to print before update action specified in the template."""
325+
return self.config_data.get("message_before_update", "")
326+
317327
@cached_property
318328
def metadata(self) -> AnyByStrDict:
319329
"""Get template metadata.

docs/configuring.md

+45
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,28 @@ The message is suppressed when Copier is run in [quiet mode][quiet].
10281028
2. Read "CONTRIBUING.md" and start coding.
10291029
```
10301030

1031+
### `message_after_update`
1032+
1033+
- Format: `str`
1034+
- CLI flags: N/A
1035+
- Default value: `""`
1036+
1037+
Like [`message_after_copy`][message_after_copy] but printed after
1038+
[_updating_](updating.md) a project.
1039+
1040+
!!! example
1041+
1042+
```yaml title="copier.yml"
1043+
project_name:
1044+
type: str
1045+
help: An awesome project needs an awesome name. Tell me yours.
1046+
1047+
_message_after_update: |
1048+
Your project "{{ project_name }}" has been updated successfully!
1049+
In case there are any conflicts, please resolve them. Then,
1050+
you're done.
1051+
```
1052+
10311053
### `message_before_copy`
10321054

10331055
- Format: `str`
@@ -1051,6 +1073,29 @@ Like [`message_after_copy`][message_after_copy] but printed _before_
10511073
generate a tailored project for you.
10521074
```
10531075

1076+
### `message_before_update`
1077+
1078+
- Format: `str`
1079+
- CLI flags: N/A
1080+
- Default value: `""`
1081+
1082+
Like [`message_before_copy`][message_after_copy] but printed before
1083+
[_updating_](updating.md) a project.
1084+
1085+
!!! example
1086+
1087+
```yaml title="copier.yml"
1088+
project_name:
1089+
type: str
1090+
help: An awesome project needs an awesome name. Tell me yours.
1091+
1092+
_message_before_update: |
1093+
Thanks for updating your project using our template.
1094+
1095+
You'll be asked a series of questions whose answers are pre-populated
1096+
with previously entered values. Feel free to change them as needed.
1097+
```
1098+
10541099
### `migrations`
10551100

10561101
- Format: `List[dict]`

0 commit comments

Comments
 (0)