Applied SymfonyStyle to all installation config customizers

This commit is contained in:
Alejandro Celaya 2017-12-31 17:07:39 +01:00
parent 0a681f0efa
commit d275316acd
4 changed files with 13 additions and 28 deletions

View File

@ -18,25 +18,23 @@ class ApplicationConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
* @param OutputInterface $output * @param OutputInterface $output
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
* @throws \Symfony\Component\Console\Exception\RuntimeException
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$io->title('APPLICATION'); $io->title('APPLICATION');
if ($appConfig->hasApp() && $io->confirm( if ($appConfig->hasApp() && $io->confirm('Do you want to keep imported application config?')) {
'<question>Do you want to keep imported application config? (Y/n):</question> '
)) {
return; return;
} }
$appConfig->setApp([ $appConfig->setApp([
'SECRET' => $this->ask( 'SECRET' => $io->ask(
$io,
'Define a secret string that will be used to sign API tokens (leave empty to autogenerate one)', 'Define a secret string that will be used to sign API tokens (leave empty to autogenerate one)',
null, null,
true function ($value) {
return $value;
}
) ?: $this->generateRandomString(32), ) ?: $this->generateRandomString(32),
]); ]);
} }

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\CLI\Install\Plugin; namespace Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
@ -35,7 +34,6 @@ class DatabaseConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
* @throws IOException * @throws IOException
* @throws RuntimeException
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
{ {

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\CLI\Install\Plugin; namespace Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
@ -18,32 +17,24 @@ class LanguageConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
* @param OutputInterface $output * @param OutputInterface $output
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
* @throws RuntimeException
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$io->title('LANGUAGE'); $io->title('LANGUAGE');
if ($appConfig->hasLanguage() && $io->confirm( if ($appConfig->hasLanguage() && $io->confirm('Do you want to keep imported language?')) {
'<question>Do you want to keep imported language? (Y/n):</question> '
)) {
return; return;
} }
$appConfig->setLanguage([ $appConfig->setLanguage([
'DEFAULT' => $io->choice( 'DEFAULT' => $this->chooseLanguage('Select default language for the application in general', $io),
'<question>Select default language for the application in general (defaults to ' 'CLI' => $this->chooseLanguage('Select default language for CLI executions', $io),
. self::SUPPORTED_LANGUAGES[0] . '):</question>',
self::SUPPORTED_LANGUAGES,
0
),
'CLI' => $io->choice(
'<question>Select default language for CLI executions (defaults to '
. self::SUPPORTED_LANGUAGES[0] . '):</question>',
self::SUPPORTED_LANGUAGES,
0
),
]); ]);
} }
private function chooseLanguage(string $message, SymfonyStyle $io): string
{
return $io->choice($message, self::SUPPORTED_LANGUAGES, self::SUPPORTED_LANGUAGES[0]);
}
} }

View File

@ -5,7 +5,6 @@ namespace Shlinkio\Shlink\CLI\Install\Plugin;
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
@ -17,7 +16,6 @@ class UrlShortenerConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
* @param OutputInterface $output * @param OutputInterface $output
* @param CustomizableAppConfig $appConfig * @param CustomizableAppConfig $appConfig
* @return void * @return void
* @throws RuntimeException
*/ */
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
{ {