@@ -11,7 +11,7 @@ class InstallCommand extends Command
11
11
*
12
12
* @var string
13
13
*/
14
- protected $ signature = 'sail:install ' ;
14
+ protected $ signature = 'sail:install {--services= : The services that should be included in the installation} ' ;
15
15
16
16
/**
17
17
* The console command description.
@@ -27,21 +27,37 @@ class InstallCommand extends Command
27
27
*/
28
28
public function handle ()
29
29
{
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
+ }
38
37
39
38
$ this ->buildDockerCompose ($ services );
40
39
$ this ->replaceEnvVariables ($ services );
41
40
42
41
$ this ->info ('Sail scaffolding installed successfully. ' );
43
42
}
44
43
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
+
45
61
/**
46
62
* Build the Docker Compose file.
47
63
*
@@ -74,10 +90,13 @@ protected function buildDockerCompose(array $services)
74
90
75
91
$ dockerCompose = file_get_contents (__DIR__ . '/../../stubs/docker-compose.stub ' );
76
92
77
- $ dockerCompose = str_replace ('{{depends}} ' , $ depends , $ dockerCompose );
93
+ $ dockerCompose = str_replace ('{{depends}} ' , empty ( $ depends ) ? '' : ' ' . $ depends , $ dockerCompose );
78
94
$ dockerCompose = str_replace ('{{services}} ' , $ stubs , $ dockerCompose );
79
95
$ dockerCompose = str_replace ('{{volumes}} ' , $ volumes , $ dockerCompose );
80
96
97
+ // Remove empty lines...
98
+ $ dockerCompose = preg_replace ("/(^[ \r\n]*|[ \r\n]+)[\s \t]*[ \r\n]+/ " , "\n" , $ dockerCompose );
99
+
81
100
file_put_contents ($ this ->laravel ->basePath ('docker-compose.yml ' ), $ dockerCompose );
82
101
}
83
102
0 commit comments