Skip to content

Commit 654020c

Browse files
Added runLocally function
Signed-off-by: Bastian Schwarz <bastian@codename-php.de>
1 parent b4df7f0 commit 654020c

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/functions/All.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use function Deployer\option;
3535
use function Deployer\parse;
3636
use function Deployer\run;
37+
use function Deployer\runLocally;
3738
use function Deployer\set;
3839
use function Deployer\upload;
3940

@@ -132,6 +133,10 @@ public function run(string $command, ?array $options = [], ?int $timeout = null,
132133
return run($command, $options, $timeout, $idle_timeout, $secret, $env, $real_time_output, $no_throw);
133134
}
134135

136+
public function runLocally(string $command, ?array $options = [], ?int $timeout = null, ?int $idle_timeout = null, ?string $secret = null, ?array $env = null, ?string $shell = null) : string {
137+
return runLocally($command, $options, $timeout, $idle_timeout, $secret, $env, $shell);
138+
}
139+
135140
public function set(string $name, mixed $value) : void {
136141
set($name, $value);
137142
}

src/functions/iRun.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,26 @@ interface iRun {
5656
* @throws Exception|RunException|TimeoutException
5757
*/
5858
public function run(string $command, ?array $options = [], ?int $timeout = null, ?int $idle_timeout = null, ?string $secret = null, ?array $env = null, ?bool $real_time_output = false, ?bool $no_throw = false) : string;
59+
60+
/**
61+
* Execute commands on a local machine.
62+
*
63+
* Examples:
64+
*
65+
* ```php
66+
* $user = runLocally('git config user.name');
67+
* runLocally("echo $user");
68+
* ```
69+
*
70+
* @param string $command Command to run on localhost.
71+
* @param array|null $options Array of options will override passed named arguments.
72+
* @param int|null $timeout Sets the process timeout (max. runtime). The timeout in seconds (default: 300 sec, `null` to disable).
73+
* @param int|null $idle_timeout Sets the process idle timeout (max. time since last output) in seconds.
74+
* @param string|null $secret Placeholder `%secret%` can be used in command. Placeholder will be replaced with this value and will not appear in any logs.
75+
* @param array|null $env Array of environment variables: `runLocally('echo $KEY', env: ['key' => 'value']);`
76+
* @param string|null $shell Shell to run in. Default is `bash -s`.
77+
*
78+
* @throws RunException
79+
*/
80+
public function runLocally(string $command, ?array $options = [], ?int $timeout = null, ?int $idle_timeout = null, ?string $secret = null, ?array $env = null, ?string $shell = null) : string;
5981
}

0 commit comments

Comments
 (0)