10000 [Console] Mention `SymfonyStyle` in helpers doc by HeahDude · Pull Request #18740 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Console] Mention SymfonyStyle in helpers doc #18740

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

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/console/helpers/formatterhelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ in the default helper set and you can get it by calling

The methods return a string, which you'll usually render to the console by
passing it to the
:method:`OutputInterface::writeln <Symfony\\Component\\Console\\Output\\OutputInterface::writeln>` method.
:method:`OutputInterface::writeln <Symfony\\Component\\Console\\Output\\OutputInterface::writeln>`
method.

.. note::

As an alternative, consider using the
:ref:`SymfonyStyle <symfony-style-blocks>` to display stylized blocks.

Print Messages in a Section
---------------------------
Expand Down
5 changes: 5 additions & 0 deletions components/console/helpers/progressbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ information, which updates as your command runs:

.. image:: /_images/components/console/progressbar.gif

.. note::

As an alternative, consider using the
:ref:`SymfonyStyle <symfony-style-progressbar>` to display a progress bar.

To display progress details, use the
:class:`Symfony\\Component\\Console\\Helper\\ProgressBar`, pass it a total
number of units, and advance the progress as the command executes::
Expand Down
47 changes: 26 additions & 21 deletions components/console/helpers/questionhelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ first argument, an :class:`Symfony\\Component\\Console\\Output\\OutputInterface`
instance as the second argument and a
:class:`Symfony\\Component\\Console\\Question\\Question` as last argument.

.. note::

As an alternative, consider using the
:ref:`SymfonyStyle <symfony-style-questions>` to ask questions.

Asking the User for Confirmation
--------------------------------

Expand Down Expand Up @@ -82,9 +87,9 @@ if you want to know a bundle name, you can add this to your command::
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');

$bundleName = $helper->ask($input, $output, $question);

// ... do something with the bundleName

return Command::SUCCESS;
}

Expand Down Expand Up @@ -120,7 +125,7 @@ from a predefined list::
$output->writeln('You have just selected: '.$color);

// ... do something with the color

return Command::SUCCESS;
}

Expand Down Expand Up @@ -162,7 +167,7 @@ this use :method:`Symfony\\Component\\Console\\Question\\ChoiceQuestion::setMult

$colors = $helper->ask($input, $output, $question);
$output->writeln('You have just selected: ' . implode(', ', $colors));

return Command::SUCCESS;
}

Expand Down Expand Up @@ -191,9 +196,9 @@ will be autocompleted as the user types::
$question->setAutocompleterValues($bundles);

$bundleName = $helper->ask($input, $output, $question);

// ... do something with the bundleName

return Command::SUCCESS;
}

Expand Down Expand Up @@ -230,9 +235,9 @@ provide a callback function to dynamically generate suggestions::
$question->setAutocompleterCallback($callback);

$filePath = $helper->ask($input, $output, $question);

// ... do something with the filePath

return Command::SUCCESS;
}

Expand All @@ -254,9 +259,9 @@ You can also specify if you want to not trim the answer by setting it directly w
$question->setTrimmable(false);
// if the users inputs 'elsa ' it will not be trimmed and you will get 'elsa ' as value
$name = $helper->ask($input, $output, $question);

// ... do something with the name

return Command::SUCCESS;
}

Expand Down Expand Up @@ -285,9 +290,9 @@ the response to a question should allow multiline answers by passing ``true`` to
$question->setMultiline(true);

$answer = $helper->ask($input, $output, $question);

// ... do something with the answer

return Command::SUCCESS;
}

Expand All @@ -313,9 +318,9 @@ convenient for passwords::
$question->setHiddenFallback(false);

$password = $helper->ask($input, $output, $question);

// ... do something with the password

return Command::SUCCESS;
}

Expand Down Expand Up @@ -347,7 +352,7 @@ convenient for passwords::
QuestionHelper::disableStty();

// ...

return Command::SUCCESS;
}

Expand Down Expand Up @@ -376,9 +381,9 @@ method::
});

$bundleName = $helper->ask($input, $output, $question);

// ... do something with the bundleName

return Command::SUCCESS;
}

Expand Down Expand Up @@ -420,9 +425,9 @@ method::
$question->setMaxAttempts(2);

$bundleName = $helper->ask($input, $output, $question);

// ... do something with the bundleName

return Command::SUCCESS;
}

Expand Down Expand Up @@ -482,9 +487,9 @@ You can also use a validator with a hidden question::
$question->setMaxAttempts(20);

$password = $helper->ask($input, $output, $question);

// ... do something with the password

return Command::SUCCESS;
}

Expand Down
9 changes: 7 additions & 2 deletions components/console/helpers/table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ When building a console application it may be useful to display tabular data:
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
+---------------+--------------------------+------------------+
.. note::

As an alternative, consider using the
:ref:`SymfonyStyle <symfony-style-content>` to display a table.

To display a table, use :class:`Symfony\\Component\\Console\\Helper\\Table`,
set the headers, set the rows and then render the table::

Expand All @@ -38,7 +43,7 @@ set the headers, set the rows and then render the table::
])
;
$table->render();

return Command::SUCCESS;
}
}
Expand Down Expand Up @@ -414,7 +419,7 @@ The only requirement to append rows is that the table must be rendered inside a
$table->render();

$table->appendRow(['Symfony']);

return Command::SUCCESS;
}
}
Expand Down
8 changes: 8 additions & 0 deletions console/style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Titling Methods

// ...

.. _symfony-style-content:

Content Methods
~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -219,6 +221,8 @@ Admonition Methods
'Aenean sit amet arcu vitae sem faucibus porta',
]);

.. _symfony-style-progressbar:

Progress Bar Methods
~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -267,6 +271,8 @@ Progress Bar Methods
Creates an instance of :class:`Symfony\\Component\\Console\\Helper\\ProgressBar`
styled according to the Symfony Style Guide.

.. _symfony-style-questions:

User Input Methods
~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -329,6 +335,8 @@ User Input Methods

$io->choice('Select the queue to analyze', ['queue1', 'queue2', 'queue3'], 'queue1');

.. _symfony-style-blocks:

Result Methods
~~~~~~~~~~~~~~

Expand Down
0