Skip to content

Commit aae7e77

Browse files
committed
Add option to install missing service dependencies
1 parent be6515f commit aae7e77

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Commands/Services/StartCommand.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function configure()
3838
->setAliases(['start'])
3939
->setDescription('Starts the specified service(s)')
4040
->addArgument('service', InputArgument::REQUIRED|InputArgument::IS_ARRAY, 'The services to start, or "all"; see <info>services:list</info> for available services')
41+
->addOption('install', 'i', InputOption::VALUE_NONE, 'Install missing dependencies before starting them, if they are not installed')
4142
->addOption('rebuild', 'b', InputOption::VALUE_NONE, 'Re-build the containers before starting')
4243
->addOption('refresh', 'r', InputOption::VALUE_NONE, 'Refresh the containers before starting; pulls all new images')
4344
->addOption('with-deps', 'd', InputOption::VALUE_NONE, 'Start all dependencies without prompting for confirmation')
@@ -73,6 +74,24 @@ private function startService(string $service): void
7374
return;
7475
}
7576

77+
if (!$service->isInstalled()) {
78+
$install = $this->tools()->input()->getOption('install');
79+
80+
if (!$install) {
81+
$install = $this->tools()->ask('service <info>%s</info> is not installed, would you like to install it? (y/n) ', false, $service->name());
82+
}
83+
84+
if ($install) {
85+
if (!$this->tools()->execute('spm services:install ' . $service->name(), $project->workingPath())) {
86+
$this->tools()->error('failed to install <info>%s</info>, re-run with -vvv to debug', $service->name());
87+
return;
88+
}
89+
} else {
90+
$this->tools()->error('service <info>%s</info> is not installed and cannot be started', $service->name());
91+
return;
92+
}
93+
}
94+
7695
if (!$service->runningContainerId()) {
7796
$this->docker->resolve($service);
7897
}

0 commit comments

Comments
 (0)