Skip to content

Commit b78093b

Browse files
committed
formatting
1 parent ef2b3f9 commit b78093b

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

bin/sail

100644100755
File mode changed.

src/Console/InstallCommand.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class InstallCommand extends Command
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'sail:install';
14+
protected $signature = 'sail:install {--services= : The services that should be included in the installation}';
1515

1616
/**
1717
* The console command description.
@@ -27,21 +27,37 @@ class InstallCommand extends Command
2727
*/
2828
public function handle()
2929
{
30-
$services = $this->choice('Which services would you like to install?', [
31-
'mysql',
32-
'pgsql',
33-
'redis',
34-
'selenium',
35-
'mailhog',
36-
'meilisearch',
37-
], 0, null, true);
30+
if ($this->option('services')) {
31+
$services = $this->option('services') == 'none' ? [] : explode(',', $this->option('services'));
32+
} elseif ($this->option('no-interaction')) {
33+
$services = ['mysql', 'redis', 'selenium', 'mailhog'];
34+
} else {
35+
$services = $this->gatherServicesWithSymfonyMenu();
36+
}
3837

3938
$this->buildDockerCompose($services);
4039
$this->replaceEnvVariables($services);
4140

4241
$this->info('Sail scaffolding installed successfully.');
4342
}
4443

44+
/**
45+
* Gather the desired Sail services using a Symfony menu.
46+
*
47+
* @return array
48+
*/
49+
protected function gatherServicesWithSymfonyMenu()
50+
{
51+
return $this->choice('Which services would you like to install?', [
52+
'mysql',
53+
'pgsql',
54+
'redis',
55+
'selenium',
56+
'mailhog',
57+
'meilisearch',
58+
], 0, null, true);
59+
}
60+
4561
/**
4662
* Build the Docker Compose file.
4763
*
@@ -74,10 +90,13 @@ protected function buildDockerCompose(array $services)
7490

7591
$dockerCompose = file_get_contents(__DIR__ . '/../../stubs/docker-compose.stub');
7692

77-
$dockerCompose = str_replace('{{depends}}', $depends, $dockerCompose);
93+
$dockerCompose = str_replace('{{depends}}', empty($depends) ? '' : ' '.$depends, $dockerCompose);
7894
$dockerCompose = str_replace('{{services}}', $stubs, $dockerCompose);
7995
$dockerCompose = str_replace('{{volumes}}', $volumes, $dockerCompose);
8096

97+
// Remove empty lines...
98+
$dockerCompose = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $dockerCompose);
99+
81100
file_put_contents($this->laravel->basePath('docker-compose.yml'), $dockerCompose);
82101
}
83102

stubs/docker-compose.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- '.:/var/www/html'
1818
networks:
1919
- sail
20-
{{depends}}
20+
{{depends}}
2121
{{services}}
2222
networks:
2323
sail:

0 commit comments

Comments
 (0)