Skip to content

Commit 39c5813

Browse files
author
Greg Bowler
committed
Extract run command to AbstractWebEngineCommand
1 parent 2a0dc6d commit 39c5813

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

src/Command/AbstractWebEngineCommand.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ public function executeScript(
4040
$scriptName,
4141
]);
4242

43-
if(!file_exists($gtCommand)) {
43+
$spacePos = strpos($gtCommand, " ");
44+
$gtCommandWithoutArguments = $gtCommand;
45+
if($spacePos > 0) {
46+
$gtCommandWithoutArguments = substr(
47+
$gtCommand,
48+
0,
49+
$spacePos
50+
);
51+
}
52+
if(!file_exists($gtCommandWithoutArguments)) {
4453
$this->writeLine(
4554
"The current directory is not a WebEngine application.",
4655
Stream::ERROR
@@ -52,8 +61,17 @@ public function executeScript(
5261
$gtCommand .= $argString;
5362
}
5463

64+
$friendlyScriptName = $gtCommandWithoutArguments;
65+
$slashPos = strrpos($gtCommandWithoutArguments, "/");
66+
if($slashPos > 0) {
67+
$friendlyScriptName = substr(
68+
$gtCommandWithoutArguments,
69+
$slashPos + 1
70+
);
71+
}
72+
5573
$process = new Process($gtCommand);
56-
$processPool->add($scriptName, $process);
74+
$processPool->add($friendlyScriptName, $process);
5775
}
5876

5977
$processPool->exec();

src/Command/RunCommand.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,17 @@
66
use Gt\Cli\Parameter\NamedParameter;
77
use Gt\Cli\Parameter\Parameter;
88
use Gt\Cli\Stream;
9+
use Gt\Daemon\Pool;
10+
use Gt\Daemon\Process;
911

10-
class RunCommand extends Command {
12+
class RunCommand extends AbstractWebEngineCommand {
1113
public function run(ArgumentValueList $arguments = null):void {
12-
$gtRunCommand = implode(DIRECTORY_SEPARATOR, [
13-
"vendor",
14-
"bin",
15-
"gt-run",
16-
]);
17-
18-
if(!file_exists($gtRunCommand)) {
19-
$this->writeLine(
20-
"The current directory is not a WebEngine application.",
21-
Stream::ERROR
22-
);
23-
return;
24-
}
25-
26-
$cmd = implode(" ", [
27-
$gtRunCommand,
28-
]);
29-
passthru($cmd);
14+
$this->executeScript(
15+
$arguments,
16+
"serve",
17+
"build --default vendor/phpgt/webengine/build.default.json --watch",
18+
"cron --watch"
19+
);
3020
}
3121

3222
public function getName():string {

0 commit comments

Comments
 (0)