diff --git a/module/CLI/src/Command/Install/InstallCommand.php b/module/CLI/src/Command/Install/InstallCommand.php
index 48a9ba3f..b537144c 100644
--- a/module/CLI/src/Command/Install/InstallCommand.php
+++ b/module/CLI/src/Command/Install/InstallCommand.php
@@ -9,6 +9,7 @@ use Shlinkio\Shlink\CLI\Install\ConfigCustomizerManagerInterface;
use Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Helper\ProcessHelper;
@@ -86,7 +87,6 @@ class InstallCommand extends Command
public function execute(InputInterface $input, OutputInterface $output): void
{
$this->io = new SymfonyStyle($input, $output);
- $this->processHelper = $this->getHelper('process');
$this->io->writeln([
'Welcome to Shlink!!',
@@ -174,9 +174,7 @@ class InstallCommand extends Command
$config = new CustomizableAppConfig();
// Ask the user if he/she wants to import an older configuration
- $importConfig = $this->io->confirm(
- 'Do you want to import previous configuration? (Y/n): '
- );
+ $importConfig = $this->io->confirm('Do you want to import configuration from previous installation?');
if (! $importConfig) {
return $config;
}
@@ -184,7 +182,7 @@ class InstallCommand extends Command
// Ask the user for the older shlink path
$keepAsking = true;
do {
- $config->setImportedInstallationPath($this->ask(
+ $config->setImportedInstallationPath($this->io->ask(
'Previous shlink installation path from which to import config'
));
$configFile = $config->getImportedInstallationPath() . '/' . self::GENERATED_CONFIG_PATH;
@@ -192,8 +190,7 @@ class InstallCommand extends Command
if (! $configExists) {
$keepAsking = $this->io->confirm(
- 'Provided path does not seem to be a valid shlink root path. '
- . 'Do you want to try another path? (Y/n): '
+ 'Provided path does not seem to be a valid shlink root path. Do you want to try another path?'
);
}
} while (! $configExists && $keepAsking);
@@ -208,37 +205,20 @@ class InstallCommand extends Command
return $config;
}
- /**
- * @param string $text
- * @param string|null $default
- * @param bool $allowEmpty
- * @return string
- * @throws RuntimeException
- */
- private function ask($text, $default = null, $allowEmpty = false): string
- {
- if ($default !== null) {
- $text .= ' (defaults to ' . $default . ')';
- }
-
- do {
- $value = $this->io->ask('' . $text . ': ', $default);
- if (empty($value) && ! $allowEmpty) {
- $this->io->writeln('Value can\'t be empty');
- }
- } while (empty($value) && $default === null && ! $allowEmpty);
-
- return $value;
- }
-
/**
* @param string $command
* @param string $errorMessage
* @param OutputInterface $output
* @return bool
+ * @throws LogicException
+ * @throws InvalidArgumentException
*/
private function runCommand($command, $errorMessage, OutputInterface $output): bool
{
+ if ($this->processHelper === null) {
+ $this->processHelper = $this->getHelper('process');
+ }
+
$process = $this->processHelper->run($output, $command);
if ($process->isSuccessful()) {
$this->io->writeln(' Success!');