Skip to content

Commit c9a2f32

Browse files
committed
[symfony#1999] Proofreading the new dialog and formatter console helpers
1 parent 009fcd7 commit c9a2f32

File tree

3 files changed

+43
-29
lines changed

3 files changed

+43
-29
lines changed

components/console/helpers/dialoghelper.rst

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ by calling :method:`Symfony\\Component\\Console\\Command\\Command::getHelperSet`
1111
$dialog = $this->getHelperSet()->get('dialog');
1212

1313
All the methods inside the Dialog Helper have an
14-
:class:`Symfony\\Component\\Console\\Output\\OutputInterface` as first argument,
15-
the question as second argument and the default value as last argument.
14+
:class:`Symfony\\Component\\Console\\Output\\OutputInterface` as first the
15+
argument, the question as the second argument and the default value as last
16+
argument.
1617

1718
Asking the User for confirmation
1819
--------------------------------
1920

2021
Suppose you want to confirm an action before actually executing it. Add
21-
the following to your command::
22+
the following to you command::
2223

2324
// ...
2425
if (!$dialog->askConfirmation(
@@ -34,7 +35,7 @@ In this case, the user will be asked "Continue with this action", and will retur
3435
argument to ``askConfirmation`` is the default value to return if the user doesn't
3536
enter any input.
3637

37-
Asking the User for information
38+
Asking the User for Information
3839
-------------------------------
3940

4041
You can also ask question with more than a simple yes/no answer. For instance,
@@ -47,16 +48,16 @@ if you want to know a bundle name, you can add this to your command::
4748
'AcmeDemoBundle'
4849
);
4950

50-
The user will be asked "Please enter the name of the bundle". They can type
51-
some name which will be returned by the ``ask`` method. If they leave it empty
51+
The user will be asked "Please enter the name of the bundle". She can type
52+
some name which will be returned by the ``ask`` method. If she leaves it empty,
5253
the default value (``AcmeDemoBundle`` here) is returned.
5354

54-
Validating the answer
55+
Validating the Answer
5556
---------------------
5657

57-
You can even validate the answer. For instance, in our last example we asked
58+
You can even validate the answer. For instance, in the last example you asked
5859
for the bundle name. Following the Symfony2 naming conventions, it should
59-
be suffixed with ``Bundle``. We can validate that by using the
60+
be suffixed with ``Bundle``. You can validate that by using the
6061
:method:`Symfony\\Component\\Console\\Helper\\DialogHelper::askAndValidate`
6162
method::
6263

@@ -87,11 +88,11 @@ This methods has 2 new arguments, the full signature is::
8788

8889
The ``$validator`` is a callback which handles the validation. It should
8990
throw an exception if there is something wrong. The exception message is displayed
90-
in the console, so it is a good practice to put some usefull information
91+
in the console, so it is a good practice to put some useful information
9192
in it.
9293

9394
You can set the max number of times to ask in the ``$attempts`` argument.
94-
If we reach this max number it will use the default value, which is given
95+
If you reach this max number it will use the default value, which is given
9596
in the last argument. Using ``false`` means the amount of attempts is infinite.
9697
The user will be asked as long as he provides an invalid answer and will only
97-
be able to proceed if his input is valid.
98+
be able to proceed if her input is valid.

components/console/helpers/formatterhelper.rst

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,41 @@ Formatter Helper
55
================
66

77
The Formatter helpers provides functions to format the output with colors.
8-
You can do more advanced things with this helper than the things in
8+
You can do more advanced things with this helper than you can in
99
:ref:`components-console-coloring`.
1010

11-
The Formatter Helper is included in the default helper set, which you can
11+
The ``formatter`` helper is included in the default helper set, which you can
1212
get by calling
1313
:method:`Symfony\\Component\\Console\\Command\\Command::getHelperSet`::
1414

1515
$formatter = $this->getHelperSet()->get('formatter');
1616

17-
The methods return a string which in most cases you want to write
18-
that data to the console with
19-
:method:`Symfony\\Component\\Console\\Output\\Output::writeln`.
17+
The methods return a string, which you'll usually render to the console by
18+
passing it to the
19+
:method:`OutputInterface::writeln<Symfony\\Component\\Console\\Output\\OutputInterface::writeln>` method.
2020

21-
Print messages in a section
21+
Print Messages in a Section
2222
---------------------------
2323

24-
Symfony uses a defined style when printing to the command line.
25-
It prints the section in color and with brackets around and the
26-
actual message behind this section indication.
24+
Symfony offers a defined style when printing a message that belongs to some
25+
"section". It prints the section in color and with brackets around it and the
26+
actual message to the right of this. Minus the color, it looks like this:
27+
28+
.. code-block:: text
29+
30+
[SomeSection] Here is some message related to that section
2731
2832
To reproduce this style, you can use the
29-
:method:`Symfony\\Component\\Console\\Helper\\FormatterHelper::formatSection`::
33+
:method:`Symfony\\Component\\Console\\Helper\\FormatterHelper::formatSection`
34+
method::
3035

31-
$formattedLine = $formatter->formatSection('SomeCommand', 'Some output from within the SomeCommand');
36+
$formattedLine = $formatter->formatSection(
37+
'SomeSection',
38+
'Here is some message related to that section'
39+
);
3240
$output->writeln($formattedLine);
3341
34-
Print messages in a block
42+
Print Messages in a Block
3543
-------------------------
3644

3745
Sometimes you want to be able to print a whole block of text with a background
@@ -40,13 +48,18 @@ color. Symfony uses this when printing error messages.
4048
If you print your error message on more than one line manually, you will
4149
notice that the background is only as long as each individual line. Use the
4250
:method:`Symfony\\Component\\Console\\Helper\\FormatterHelper::formatBlock`
43-
togenerate a block output::
51+
to generate a block output::
4452

4553
$errorMessages = array('Error!', 'Something went wrong');
4654
$formattedBlock = $formatter->formatBlock($errorMessages, 'error');
55+
$output->writeln($formattedBlock);
4756
4857
As you can see, passing an array of messages to the
4958
:method:`Symfony\\Component\\Console\\Helper\\FormatterHelper::formatBlock`
5059
method creates the desired output. If you pass ``true`` as third parameter, the
51-
block will be formatted with more padding (one blank line above and below the
52-
messages and 2 spaces on the left and right).
60+
block will be formatted with more padding (one blank line above and below the
61+
messages and 2 spaces on the left and right).
62+
63+
The exact "style" you use in the block is up to you. In this case, you're using
64+
the pre-defined ``error`` style, but there are other styles, or you can create
65+
your own. See :ref:`components-console-coloring`.

components/console/introduction.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ Console Helpers
275275
The console component also contains a set of "helpers" - different small
276276
tools capable of helping you with different tasks:
277277

278-
* :doc:`/component/console/helpers/dialoghelper`: interactively ask the user for information
279-
* :doc:`/component/console/helpers/formatterhelper`: customize the output colorization
278+
* :doc:`/components/console/helpers/dialoghelper`: interactively ask the user for information
279+
* :doc:`/components/console/helpers/formatterhelper`: customize the output colorization
280280

281281
Testing Commands
282282
----------------

0 commit comments

Comments
 (0)