Skip to content

Commit 136c5a4

Browse files
committed
Prompt the user to fill in a description for their Invokable command
1 parent 888e580 commit 136c5a4

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/Maker/MakeCommand.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\Console\Input\InputInterface;
2929
use Symfony\Component\Console\Input\InputOption;
3030
use Symfony\Component\Console\Output\OutputInterface;
31+
use Symfony\Component\Console\Question\Question;
3132
use Symfony\Component\Console\Style\SymfonyStyle;
3233
use Symfony\Component\HttpKernel\Kernel;
3334

@@ -90,6 +91,14 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
9091
$input->getOption('invokable') ?
9192
$this->generateInvokableCommand($commandName, $commandClassNameDetails, $io, $generator) :
9293
$this->generateInheritanceCommand($commandName, $commandClassNameDetails, $io, $generator);
94+
95+
$generator->writeChanges();
96+
97+
$this->writeSuccessMessage($io);
98+
$io->text([
99+
'Next: open your new command class and customize it!',
100+
'Find the documentation at <fg=yellow>https://symfony.com/doc/current/console.html</>',
101+
]);
93102
}
94103

95104
private function generateInheritanceCommand(string $commandName, ClassNameDetails $commandClassNameDetails, ConsoleStyle $io, Generator $generator): void
@@ -113,18 +122,12 @@ private function generateInheritanceCommand(string $commandName, ClassNameDetail
113122
'set_description' => !class_exists(LazyCommand::class),
114123
]
115124
);
116-
117-
$generator->writeChanges();
118-
119-
$this->writeSuccessMessage($io);
120-
$io->text([
121-
'Next: open your new command class and customize it!',
122-
'Find the documentation at <fg=yellow>https://symfony.com/doc/current/console.html</>',
123-
]);
124125
}
125126

126127
private function generateInvokableCommand(string $commandName, ClassNameDetails $commandClassNameDetails, ConsoleStyle $io, Generator $generator): void
127128
{
129+
$description = $io->ask('Enter a short description for your command');
130+
128131
$useStatements = new UseStatementGenerator([
129132
Argument::class,
130133
AsCommand::class,
@@ -139,16 +142,9 @@ private function generateInvokableCommand(string $commandName, ClassNameDetails
139142
[
140143
'use_statements' => $useStatements,
141144
'command_name' => $commandName,
145+
'command_description' => $description,
142146
]
143147
);
144-
145-
$generator->writeChanges();
146-
147-
$this->writeSuccessMessage($io);
148-
$io->text([
149-
'Next: open your new command class and customize it!',
150-
'Find the documentation at <fg=yellow>https://symfony.com/doc/current/console.html</>',
151-
]);
152148
}
153149

154150
public function configureDependencies(DependencyBuilder $dependencies): void

templates/command/Command.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#[AsCommand(
88
name: '<?= $command_name; ?>',
9-
description: 'Add a short description for your command',
9+
description: '<?= $command_description; ?>',
1010
)]
1111
class <?= $class_name; ?>
1212
{

0 commit comments

Comments
 (0)