Skip to content

[Console] Document #[Ask] and #[Interact] attributes#22109

Open
lacatoire wants to merge 4 commits intosymfony:7.4from
lacatoire:doc-ask-interact
Open

[Console] Document #[Ask] and #[Interact] attributes#22109
lacatoire wants to merge 4 commits intosymfony:7.4from
lacatoire:doc-ask-interact

Conversation

@lacatoire
Copy link
Contributor

Document the #[Ask] and #[Interact] attributes for interactive invokable commands: simple prompts, hidden input, confirmation, DTO properties, custom interact methods, and execution order.

Fixes #21465

@MrYamous
Copy link
Contributor

MrYamous commented Mar 5, 2026

Could you please add those attributes in reference page ?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Documents the new Console interactive invokable-command attributes (#[Ask] and #[Interact]) introduced in Symfony 7.4, addressing the missing documentation requested in issue #21465.

Changes:

  • Add #[Ask] documentation covering basic prompts, hidden input, confirmations, and usage on DTO properties.
  • Add #[Interact] documentation for custom interactive logic and describe execution order.
  • Link Ask and Interact from the Symfony attributes index.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
reference/attributes.rst Adds references for Ask and Interact to the attributes overview list.
console/input.rst Introduces a new “Interactive Input” section documenting #[Ask] and #[Interact] with examples and execution order.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

#[Interact]
public function prompt(SymfonyStyle $io): void
{
if (!isset($this->password)) {
public function __invoke(
#[Option]
#[Ask('Do you want to activate the user?')]
bool $active,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options shouldn't be required, they should define a default value, which means interactive attributes can't be used with them.

This code will currently raise an exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might deserve a clear note: interactive attributes can only be used with required console arguments.

Using them with optional arguments wouldn't work either, since prompting for those values when they are missing would contradict the purpose of optional inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Console] Add support for interactive invokable commands with `#[Intera…

6 participants