Skip to content

Commit

Permalink
Merge pull request #379 from loic425/feature/use-symfony-style
Browse files Browse the repository at this point in the history
Use Symfony style for commands
  • Loading branch information
loic425 committed Jan 3, 2022
2 parents a5e8b09 + c43beb4 commit 2fd9a2c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class InstallAssetsCommand extends Command
{
Expand Down Expand Up @@ -41,7 +42,8 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(sprintf('Installing AppName assets for environment <info>%s</info>.', $this->environment));
$io = new SymfonyStyle($input, $output);
$io->title(sprintf('Installing AppName assets for environment <info>%s</info>.', $this->environment));

$commands = [
'assets:install',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$outputStyle = new SymfonyStyle($input, $output);
$outputStyle->writeln('<info>Installing AppName...</info>');
$outputStyle->writeln($this->getLogo());
$io = new SymfonyStyle($input, $output);
$io->title('Installing AppName...');
$io->writeln($this->getLogo());

$errored = false;
foreach ($this->commands as $step => $command) {
try {
$outputStyle->newLine();
$outputStyle->section(sprintf(
$io->newLine();
$io->section(sprintf(
'Step %d of %d. <info>%s</info>',
$step + 1,
count($this->commands),
Expand All @@ -84,19 +84,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$output->writeln($this->getProperFinalMessage($errored));
$output->writeln('You can now open your website at the following path under the website root.');
$io->newLine(2);
$io->success($this->getProperFinalMessage($errored));
$io->info('You can now open your website at the following path under the website root: /');

return 0;
}

private function getProperFinalMessage(bool $errored): string
{
if ($errored) {
return '<info>AppName has been installed, but some error occurred.</info>';
return 'AppName has been installed, but some error occurred.';
}

return '<info>AppName has been successfully installed.</info>';
return 'AppName has been successfully installed.';
}

private function getLogo(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$outputStyle = new SymfonyStyle($input, $output);
$outputStyle->writeln(sprintf(
$io = new SymfonyStyle($input, $output);
$io->writeln(sprintf(
'Creating AppName database for environment <info>%s</info>.',
$this->environment
));
Expand All @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->getCommands($input, $output, $this->getHelper('question'))
;
$this->commandsRunner->run($commands, $input, $output, $this->getApplication());
$outputStyle->newLine();
$io->newLine();

// Install Sample data command is available on monofony/fixtures-plugin
if (class_exists(InstallSampleDataCommand::class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getHelper('question');

$outputStyle = new SymfonyStyle($input, $output);
$outputStyle->newLine();
$outputStyle->writeln(sprintf(
$io = new SymfonyStyle($input, $output);
$io->newLine();
$io->title(sprintf(
'Loading sample data for environment <info>%s</info>.',
$this->environment
));

$outputStyle->writeln('<error>Warning! This action will erase your database.</error>');
$io->warning('This action will erase your database.');

if (!$questionHelper->ask($input, $output, new ConfirmationQuestion('Continue? (y/N) ', false))) {
$outputStyle->writeln('Cancelled loading sample data.');
$io->writeln('Cancelled loading sample data.');

return 0;
}
Expand All @@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
];

$this->commandsRunner->run($commands, $input, $output, $this->getApplication());
$outputStyle->newLine(2);
$io->newLine(2);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ConstraintViolationListInterface;
Expand Down Expand Up @@ -58,7 +59,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

protected function setupAdministratorUser(InputInterface $input, OutputInterface $output): void
{
$output->writeln('Create your administrator account.');
$io = new SymfonyStyle($input, $output);
$io->writeln('Create your administrator account.');

try {
$user = $this->configureNewUser($this->adminUserFactory->createNew(), $input, $output);
Expand All @@ -71,7 +73,7 @@ protected function setupAdministratorUser(InputInterface $input, OutputInterface
$this->adminUserManager->persist($user);
$this->adminUserManager->flush();

$output->writeln('Administrator account successfully registered.');
$io->success('Administrator account successfully registered.');
}

private function configureNewUser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class CreateClientCommand extends Command
{
Expand Down Expand Up @@ -52,13 +53,15 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

/** @var Client $client */
$client = $this->clientManager->createClient();
$client->setRedirectUris($input->getOption('redirect-uri'));
$client->setAllowedGrantTypes($input->getOption('grant-type'));
$this->clientManager->updateClient($client);

$output->writeln(
$io->writeln(
sprintf(
'A new client with public id <info>%s</info>, secret <info>%s</info> has been added',
$client->getPublicId(),
Expand Down

0 comments on commit 2fd9a2c

Please sign in to comment.