Skip to content

Commit 7b11d3c

Browse files
committed
refactor: rename for clarity that it is an arbitrary path setting
1 parent 46d7e40 commit 7b11d3c

3 files changed

Lines changed: 29 additions & 17 deletions

File tree

docs/hosts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ host('example.org')
7878

7979
### Path
8080

81-
You can store an arbitrary path string in the `path` config (for example to reuse in `{{path}}` placeholders). On a host, prefer `setPath()` over `set('path', …)` so the value is typed as a string and IDEs or static analysis can catch mistakes such as passing a number, which the generic `set()` method does not flag. In the recipe file (outside a host definition), use the global [set()](api.md#set) function—for example `set('path', '/var/www/myapp')`.
81+
You can store an arbitrary path string in the `path` config (for example to reuse in `{{path}}` placeholders). On a host, prefer `setPathConfig()` over `set('path', …)` so the name reflects that this is the `path` *configuration* value (and not, for example, the deployment root), and so the value is typed as a string. IDEs or static analysis can then catch mistakes such as passing a number, which the generic `set()` method does not flag. In the recipe file (outside a host definition), use the global [set()](api.md#set) function—for example `set('path', '/var/www/myapp')`.
8282

8383
```php
84-
host('example.org')->setPath('/var/www/myapp');
84+
host('example.org')->setPathConfig('/var/www/myapp');
8585

8686
set('path', '/var/www/myapp');
8787
```
@@ -138,7 +138,7 @@ set('default_selector', "stage=prod&role=web,role=special");
138138
| **`port`** | SSH port. Default is `22`. |
139139
| **`config_file`** | SSH config file location. Default is `~/.ssh/config`. |
140140
| **`identity_file`** | SSH private key file. E.g., `~/.ssh/id_rsa`. |
141-
| **`path`** | Optional path string for custom use (e.g. `{{path}}`). Use `setPath()` on the host for a typed setter. |
141+
| **`path`** | Optional path string for custom use (e.g. `{{path}}`). Use `setPathConfig()` on the host for a typed setter. |
142142
| **`forward_agent`** | Enable SSH agent forwarding. Default is `true`. |
143143
| **`ssh_multiplexing`** | Enable SSH multiplexing for performance. Default is `true`. |
144144
| **`shell`** | Shell to use. Default is `bash -ls`. |

src/Host/Host.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,6 @@ public function getPort(): int|string|null
123123
return $this->config->get('port', null);
124124
}
125125

126-
public function setPath(string $path): self
127-
{
128-
$this->config->set('path', $path);
129-
return $this;
130-
}
131-
132-
public function getPath(): ?string
133-
{
134-
return $this->config->get('path', null);
135-
}
136-
137126
public function setConfigFile(string $file): self
138127
{
139128
$this->config->set('config_file', $file);
@@ -211,6 +200,29 @@ public function getDeployPath(): ?string
211200
return $this->config->get('deploy_path', null);
212201
}
213202

203+
/**
204+
* Set the optional `path` configuration value (the `path` key).
205+
*
206+
* Use it for recipe-defined or host-specific data exposed as `{{path}}` in task strings. This is
207+
* not the remote deployment root; for that, use `setDeployPath()`.
208+
*/
209+
public function setPathConfig(string $value): self
210+
{
211+
$this->config->set('path', $value);
212+
return $this;
213+
}
214+
215+
/**
216+
* Get the optional `path` configuration value, or `null` if the key is not set.
217+
*
218+
* This is the `path` key (e.g. for `{{path}}` in tasks), not the remote deployment directory;
219+
* for that, use `getDeployPath()`.
220+
*/
221+
public function getPathConfig(): ?string
222+
{
223+
return $this->get('path', null);
224+
}
225+
214226
public function setLabels(array $labels): self
215227
{
216228
$this->config->set('labels', $labels);

tests/src/Host/HostTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testHost()
3030
$host
3131
->setHostname('hostname')
3232
->setRemoteUser('remote_user')
33-
->setPath('/var/www')
33+
->setPathConfig('/var/www')
3434
->setPort(22)
3535
->setConfigFile('~/.ssh/config')
3636
->setIdentityFile('~/.ssh/id_rsa')
@@ -41,7 +41,7 @@ public function testHost()
4141
self::assertStringContainsString('host', $host->getTag());
4242
self::assertEquals('hostname', $host->getHostname());
4343
self::assertEquals('remote_user', $host->getRemoteUser());
44-
self::assertEquals('/var/www', $host->getPath());
44+
self::assertEquals('/var/www', $host->getPathConfig());
4545
self::assertEquals(22, $host->getPort());
4646
self::assertEquals('~/.ssh/config', $host->getConfigFile());
4747
self::assertEquals('~/.ssh/id_rsa', $host->getIdentityFile());
@@ -89,7 +89,7 @@ public function testHostWithPathFromParams()
8989
->set('env', $value)
9090
->set('path', '{{env}}');
9191

92-
self::assertEquals($value, $host->getPath());
92+
self::assertEquals($value, $host->getPathConfig());
9393
}
9494

9595
public function testHostWithUserFromConfig()

0 commit comments

Comments
 (0)