Skip to content

Commit 82b4e84

Browse files
author
Gareth Midwood
committed
Add env:watch command. Stop env:start from running as runExternalCommand
1 parent e15d8ef commit 82b4e84

4 files changed

Lines changed: 74 additions & 1 deletion

File tree

cdev.services.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
class="Cdev\Docker\Environment\Command\Container\Drush">
3434
</service>
3535

36+
<service id="cdev.docker_watch_command"
37+
class="Cdev\Docker\Environment\Command\WatchEnvCommand">
38+
</service>
39+
3640

3741
<!-- Environments -->
3842

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
namespace Creode\Cdev\Command\Env;
3+
4+
use Creode\Cdev\Command\Env\EnvCommand;
5+
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Input\InputOption;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class WatchEnvCommand extends EnvCommand
11+
{
12+
protected function configure()
13+
{
14+
$this->setName('env:watch');
15+
$this->setDescription('Watches the environment for log messages');
16+
17+
$this->addOption(
18+
'path',
19+
'p',
20+
InputOption::VALUE_REQUIRED,
21+
'Path to run commands on. Defaults to the directory the command is run from',
22+
getcwd()
23+
);
24+
}
25+
26+
protected function execute(InputInterface $input, OutputInterface $output)
27+
{
28+
$this->_environment->input($input);
29+
30+
$output->writeln(
31+
$this->_environment->watch()
32+
);
33+
}
34+
}

src/Environment/Docker.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ public function start()
118118
$this->_compose->up($path, $build);
119119
}
120120

121+
public function watch()
122+
{
123+
$this->logTitle('Watching dev environment logs...');
124+
125+
$path = $this->_input->getOption('path');
126+
127+
$this->_compose->logs($path);
128+
}
129+
121130
public function stop()
122131
{
123132
$this->logTitle('Stopping dev environment...');

src/Environment/System/Compose/Compose.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,37 @@ public function up($path, $build = false)
5656
array_push($params, '--build');
5757
}
5858

59-
$this->runExternalCommand(self::COMMAND, $params, $path);
59+
$this->run(self::COMMAND, $params, $path);
6060

6161
return self::COMMAND . ' up completed';
6262
}
6363

64+
/**
65+
* Watchs the logs for the environment
66+
* @param string $path
67+
* @return string
68+
*/
69+
public function logs($path)
70+
{
71+
$this->requiresConfig();
72+
73+
$this->run(
74+
self::COMMAND,
75+
[
76+
'-f',
77+
Config::CONFIG_DIR . self::FILE,
78+
'-p',
79+
$this->_networkName,
80+
'logs',
81+
'-f', // --follow
82+
'-t' // --timestamps
83+
],
84+
$path
85+
);
86+
87+
return self::COMMAND . ' logs running';
88+
}
89+
6490
/**
6591
* Stops environment
6692
* @param string $path

0 commit comments

Comments
 (0)