-
-
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 |
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 |
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.
Yonel, thanks a lot for this massive contribution 🙇
I agree with what you said here:
we can go ahead and merge this one, then open a new PR for the remaining updates
I'll wait a bit to read more opinions, but that's the plan I'd like to follow. Thanks!
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 agree with doing the work in steps, but I think the order should be swapped around.
We can't update all examples across the documentation to use features that we didn't document properly in my opinion. This applies in particular to console/input.rst
, which has to be updated before we can start using #[Option]
/#[Argument]
in the documentation.
But it would be perfectly fine if all articles in the docs still have outdated (too complex) examples, but the main guides are updated to document both the simple + advanced way.
We must also be careful about updating an example without updating the context it is placed in (I tried to comment on those cases whenever I saw this).
console.rst
Outdated
leverage advanced features like lifecycle hooks: :method:`Symfony\\Component\\Console\\Command\\Command::initialize`, | ||
:method:`Symfony\\Component\\Console\\Command\\Command::interact`, and built-in helpers. |
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.
leverage advanced features like lifecycle hooks: :method:`Symfony\\Component\\Console\\Command\\Command::initialize`, | |
:method:`Symfony\\Component\\Console\\Command\\Command::interact`, and built-in helpers. | |
leverage advanced features like lifecycle hooks (e.g. :method:`Symfony\\Component\\Console\\Command\\Command::initialize` and | |
:method:`Symfony\\Component\\Console\\Command\\Command::interact`) and built-in helpers. |
Additionally, you can extend the :class:`Symfony\\Component\\Console\\Command\\Command` class to | ||
leverage advanced features like lifecycle hooks: :method:`Symfony\\Component\\Console\\Command\\Command::initialize`, | ||
:method:`Symfony\\Component\\Console\\Command\\Command::interact`, and built-in helpers. | ||
|
||
Configuring the Command |
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 whole section needs updating, the text currently no longer matches the updated code example.
I think we can remove it completely, and instead merge it with the previous section. Something like
You can also use ``#[AsCommand]`` to add a description and longer help text for the command::
// src/Command/CreateUserCommand.php
#[AsCommand(
name: 'app:create-user',
description: 'Creates a new user.', // the command description shown when running "php bin/console list"
help: 'This command allows you to create a user...', // the command help shown when running the command with the "--help" option
)]
class CreateUserCommand
{
public function __invoke(): int
{
// ...
}
}
Additionally, you can extend the :class:`Symfony\\Component\\Console\\Command\\Command`
class to leverage advanced features like lifecycle hooks (e.g.
:method:`Symfony\\Component\\Console\\Command\\Command::initialize`,
:method:`Symfony\\Component\\Console\\Command\\Command::interact`) and built-in
helpers.
// the command help shown when running the command with the "--help" option | ||
->setHelp('This command allows you to create a user...') | ||
; | ||
// ... | ||
} | ||
} | ||
|
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.
The next section ("Registering the Command") also needs rework, the document now only shows the #[AsCommand]
examples, so "You can register the command by adding the AsCommand attribute to it:" is out of place now.
However, we need to document the final paragraph ("If you can't use PHP attributes, register the command as a service [...]") somewhere in this article I think.
// ... | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
public function __invoke(OutputInterface $output, #[Argument] string $username, #[Argument] string $password): int |
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 PR doesn't update https://symfony.com/doc/current/console/input.html (not sure if that is intentional). This means that we never documented #[Argument]
or #[Option]
.
I don't think it's a good idea to update other examples with these attributes as long as we don't document the attributes themselves.
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 agree. input.rst
is one of the pending documents to update.
Thanks @wouterj, @94noni, and @javiereguiluz for your feedback! I will try to address it ASAP |
d05dc2a
to
3986174
Compare
244cf19
to
165f6c9
Compare
165f6c9
to
7443201
Compare
Closes #20553
Pending docs to be updated: