Skip to content

Commit d3265c0

Browse files
committed
feat: add typed setPath
1 parent fd08d3f commit d3265c0

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

docs/hosts.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ host('example.org')
7676
->setRemoteUser('deployer');
7777
```
7878

79+
### Path
80+
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')`.
82+
83+
```php
84+
host('example.org')->setPath('/var/www/myapp');
85+
86+
set('path', '/var/www/myapp');
87+
```
88+
7989
---
8090

8191
## Host Labels
@@ -128,6 +138,7 @@ set('default_selector', "stage=prod&role=web,role=special");
128138
| **`port`** | SSH port. Default is `22`. |
129139
| **`config_file`** | SSH config file location. Default is `~/.ssh/config`. |
130140
| **`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. |
131142
| **`forward_agent`** | Enable SSH agent forwarding. Default is `true`. |
132143
| **`ssh_multiplexing`** | Enable SSH multiplexing for performance. Default is `true`. |
133144
| **`shell`** | Shell to use. Default is `bash -ls`. |

src/Host/Host.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ 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+
126137
public function setConfigFile(string $file): self
127138
{
128139
$this->config->set('config_file', $file);

tests/src/Host/HostTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function testHost()
3030
$host
3131
->setHostname('hostname')
3232
->setRemoteUser('remote_user')
33+
->setPath('/var/www')
3334
->setPort(22)
3435
->setConfigFile('~/.ssh/config')
3536
->setIdentityFile('~/.ssh/id_rsa')
@@ -40,6 +41,7 @@ public function testHost()
4041
self::assertStringContainsString('host', $host->getTag());
4142
self::assertEquals('hostname', $host->getHostname());
4243
self::assertEquals('remote_user', $host->getRemoteUser());
44+
self::assertEquals('/var/www', $host->getPath());
4345
self::assertEquals(22, $host->getPort());
4446
self::assertEquals('~/.ssh/config', $host->getConfigFile());
4547
self::assertEquals('~/.ssh/id_rsa', $host->getIdentityFile());

0 commit comments

Comments
 (0)