Skip to content

Commit

Permalink
determine if we can use attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrushlow committed Apr 5, 2021
1 parent 85761bd commit 3ca3736
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Maker/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\LazyCommand;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -63,6 +64,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
[
'command_name' => $commandName,
'set_description' => !class_exists(LazyCommand::class),
'attribute_class_exists' => class_exists(AsCommand::class),
]
);

Expand Down
5 changes: 4 additions & 1 deletion src/Resources/skeleton/command/Command.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

namespace <?= $namespace; ?>;

<?php if ($use_attributes && $attribute_class_exists): ?>
use Symfony\Component\Console\Attribute\AsCommand;
<?php endif; ?>
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

<?php if ($use_attributes): ?>
<?php if ($use_attributes && $attribute_class_exists): ?>
#[ConsoleCommand(
name: '<?= $command_name; ?>',
description: 'Add a short description for your command',
Expand Down

0 comments on commit 3ca3736

Please sign in to comment.