-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Console] Document invokable command #20932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.3
Are you sure you want to change the base?
Conversation
42c2a79
to
3d9b930
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the harmonization of some command names 👍
#[AsCommand(name: 'app:create-user')] | ||
class CreateUserCommand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should make all these changes with the #AsCommand attribute in a separate PR to avoid growing this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d actually prefer to keep all these related changes in a single PR, since they’re closely tied together. It helps keep the context in one place and makes it easier to review everything as a whole.
In any case, we can go ahead and merge this one, then open a new PR for the remaining updates.
Thanks @alamirault and @OskarStark for your review 🙏 I’m actively looking for someone to help me refactor |
// ... | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
public function __invoke(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$helper = $this->getHelper('question'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this wont work isnt it ?
or are those console helper injectable in some ways ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Yes, there is a way, but I’m not sure if it’s simpler to extend Command or to get the helper via:
public function __invoke(InputInterface $input, OutputInterface $output, Application $application): int
{
$helper = $application->getHelperSet()->get('question');
// ...
}
Anyway, this all looks old-fashioned, because SymfonyStyle can do it better. There’s even a note right at the beginning:
.. note::
As an alternative, consider using the
:ref:`SymfonyStyle <symfony-style-questions>` to ask questions.
IMO, it’s not just an alternative, but the simplest way to ask questions from now on:
public function __invoke(SymfonyStyle $io): int
{
$answer = $io->ask(...);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do the same here as with invokable commands: start with the simpler approach (SymfonyStyle), then mention alternatives for custom needs. wdyt @symfony/docs ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for documentation I agree yes, basic usage then more advance 👍🏻
a question just: cant we imagine those helper as console service as injectable in the invoke method ? (can open an dedicated issue for later :))
I would also add https://symfony.com/doc/current/console/input.html, wdyt @yceruto ? |
Thanks, Antoine! Sure, go for it. Here we're discussing input related topics symfony/symfony#59602 |
Closes #20553
Pending docs to be updated: