Skip to content

Commit 381115e

Browse files
authored
Enhance documentation with dynamic config example (#4119)
* Enhance documentation with dynamic config example Added note on dynamic configuration syntax for overridden options. * Add comments
1 parent 89ff232 commit 381115e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/basics.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,35 @@ task my_task
239239

240240
Since `current_date` is overridden, the callback is never executed.
241241

242+
:::note
243+
If you need to create a new configuration option based on the overridden one, use dynamic configuration syntax:
244+
245+
```php
246+
247+
set('dir_name', 'test');
248+
249+
// calling get during recipe initialization will give you the original value defined above
250+
set('uses_original_dir_name', '/path/to/' . get('dir_name'));
251+
252+
// use dynamic configuration syntax if you need to get a value passed via -o option
253+
set('uses_overridden_dir_name', function () {
254+
return '/path/to/' . get('dir_name');
255+
});
256+
257+
task('my_task', function () {
258+
writeln('Path: {{uses_original_dir_name}}');
259+
writeln('Path: {{uses_overridden_dir_name}}');
260+
});
261+
```
262+
263+
```sh
264+
$ dep my_task deployer.org -v -o dir_name="prod"
265+
task my_task
266+
[deployer.org] Path: /path/to/test
267+
[deployer.org] Path: /path/to/prod
268+
```
269+
:::
270+
242271
---
243272

244273
By now, you should have a solid understanding of Deployer’s basics, from defining tasks and hosts to working with

0 commit comments

Comments
 (0)