Skip to content

Commit 446b986

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: [Console] Improve console events doc [Console] Mention `SymfonyStyle` in helpers doc [Console] Add `ProcessHelper` link to the list of helpers
2 parents 25ae438 + da759ef commit 446b986

File tree

9 files changed

+67
-21
lines changed

9 files changed

+67
-21
lines changed

components/console/events.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ the wheel, it uses the Symfony EventDispatcher component to do the work::
1717
.. caution::
1818

1919
Console events are only triggered by the main command being executed.
20-
Commands called by the main command will not trigger any event.
20+
Commands called by the main command will not trigger any event, unless
21+
run by the application itself, see :doc:`/console/calling_commands`.
2122

2223
The ``ConsoleEvents::COMMAND`` Event
2324
------------------------------------

components/console/helpers/formatterhelper.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ in the default helper set and you can get it by calling
1313

1414
The methods return a string, which you'll usually render to the console by
1515
passing it to the
16-
:method:`OutputInterface::writeln <Symfony\\Component\\Console\\Output\\OutputInterface::writeln>` method.
16+
:method:`OutputInterface::writeln <Symfony\\Component\\Console\\Output\\OutputInterface::writeln>`
17+
method.
18+
19+
.. note::
20+
21+
As an alternative, consider using the
22+
:ref:`SymfonyStyle <symfony-style-blocks>` to display stylized blocks.
1723

1824
Print Messages in a Section
1925
---------------------------

components/console/helpers/processhelper.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
Process Helper
22
==============
33

4-
The Process Helper shows processes as they're running and reports
5-
useful information about process status.
4+
The Process Helper shows processes as they're running and reports useful
5+
information about process status.
66

7-
To display process details, use the :class:`Symfony\\Component\\Console\\Helper\\ProcessHelper`
8-
and run your command with verbosity. For example, running the following code with
7+
To display process details, use the
8+
:class:`Symfony\\Component\\Console\\Helper\\ProcessHelper` and run your command
9+
with verbosity. For example, running the following code with
910
a very verbose verbosity (e.g. ``-vv``)::
1011

1112
use Symfony\Component\Process\Process;

components/console/helpers/progressbar.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ information, which updates as your command runs:
66

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

9+
.. note::
10+
11+
As an alternative, consider using the
12+
:ref:`SymfonyStyle <symfony-style-progressbar>` to display a progress bar.
13+
914
To display progress details, use the
1015
:class:`Symfony\\Component\\Console\\Helper\\ProgressBar`, pass it a total
1116
number of units, and advance the progress as the command executes::

components/console/helpers/questionhelper.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ first argument, an :class:`Symfony\\Component\\Console\\Output\\OutputInterface`
1515
instance as the second argument and a
1616
:class:`Symfony\\Component\\Console\\Question\\Question` as last argument.
1717

18+
.. note::
19+
20+
As an alternative, consider using the
21+
:ref:`SymfonyStyle <symfony-style-questions>` to ask questions.
22+
1823
Asking the User for Confirmation
1924
--------------------------------
2025

components/console/helpers/table.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ When building a console application it may be useful to display tabular data:
1414
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
1515
+---------------+--------------------------+------------------+
1616
17+
.. note::
18+
19+
As an alternative, consider using the
20+
:ref:`SymfonyStyle <symfony-style-content>` to display a table.
21+
1722
To display a table, use :class:`Symfony\\Component\\Console\\Helper\\Table`,
1823
set the headers, set the rows and then render the table::
1924

@@ -38,7 +43,7 @@ set the headers, set the rows and then render the table::
3843
])
3944
;
4045
$table->render();
41-
46+
4247
return Command::SUCCESS;
4348
}
4449
}
@@ -435,7 +440,7 @@ The only requirement to append rows is that the table must be rendered inside a
435440
$table->render();
436441

437442
$table->appendRow(['Symfony']);
438-
443+
439444
return Command::SUCCESS;
440445
}
441446
}

console.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,12 @@ registers an :doc:`event subscriber </event_dispatcher>` to listen to the
577577
:ref:`ConsoleEvents::TERMINATE event <console-events-terminate>` and adds a log
578578
message whenever a command doesn't finish with the ``0`` `exit status`_.
579579

580+
Using Events And Handling Signals
581+
---------------------------------
582+
583+
When a command is running, many events are dispatched, one of them allows to
584+
react to signals, read more in :doc:`this section </components/console/events>`.
585+
580586
Learn More
581587
----------
582588

@@ -596,6 +602,7 @@ tools capable of helping you with different tasks:
596602
* :doc:`/components/console/helpers/table`: displays tabular data as a table
597603
* :doc:`/components/console/helpers/debug_formatter`: provides functions to
598604
output debug information when running an external program
605+
* :doc:`/components/console/helpers/processhelper`: allows to run processes using ``DebugProcessHelper``
599606
* :doc:`/components/console/helpers/cursor`: allows to manipulate the cursor in the terminal
600607

601608
.. _`exit status`: https://en.wikipedia.org/wiki/Exit_status

console/calling_commands.rst

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ or if you want to create a "meta" command that runs a bunch of other commands
88
changed on the production servers: clearing the cache, generating Doctrine
99
proxies, dumping web assets, ...).
1010

11-
Use the :method:`Symfony\\Component\\Console\\Application::find` method to
12-
find the command you want to run by passing the command name. Then, create a
13-
new :class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the
14-
arguments and options you want to pass to the command.
11+
Use the :method:`Symfony\\Component\\Console\\Application::doRun`. Then, create
12+
a new :class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the
13+
arguments and options you want to pass to the command. The command name must be
14+
the first argument.
1515

16-
Eventually, calling the ``run()`` method actually runs the command and returns
17-
the returned code from the command (return value from command's ``execute()``
16+
Eventually, calling the ``doRun()`` method actually runs the command and returns
17+
the returned code from the command (return value from command ``execute()``
1818
method)::
1919

2020
// ...
@@ -29,15 +29,14 @@ method)::
2929

3030
protected function execute(InputInterface $input, OutputInterface $output): int
3131
{
32-
$command = $this->getApplication()->find('demo:greet');
33-
34-
$arguments = [
32+
$greetInput = new ArrayInput([
33+
// the command name is passed as first argument
34+
'command' => 'demo:greet',
3535
'name' => 'Fabien',
3636
'--yell' => true,
37-
];
37+
]);
3838

39-
$greetInput = new ArrayInput($arguments);
40-
$returnCode = $command->run($greetInput, $output);
39+
$returnCode = $this->getApplication()->doRun($greetInput, $output);
4140

4241
// ...
4342
}
@@ -47,7 +46,16 @@ method)::
4746

4847
If you want to suppress the output of the executed command, pass a
4948
:class:`Symfony\\Component\\Console\\Output\\NullOutput` as the second
50-
argument to ``$command->run()``.
49+
argument to ``$application->doRun()``.
50+
51+
.. note::
52+
53+
Using ``doRun()`` instead of ``run()`` prevents autoexiting and allows to
54+
return the exit code instead.
55+
56+
Also, using ``$this->getApplication()->doRun()`` instead of
57+
``$this->getApplication()->find('demo:greet')->run()`` will allow proper
58+
events to be dispatched for that inner command as well.
5159

5260
.. caution::
5361

console/style.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ Titling Methods
9696

9797
// ...
9898

99+
.. _symfony-style-content:
100+
99101
Content Methods
100102
~~~~~~~~~~~~~~~
101103

@@ -215,6 +217,8 @@ Admonition Methods
215217
'Aenean sit amet arcu vitae sem faucibus porta',
216218
]);
217219

220+
.. _symfony-style-progressbar:
221+
218222
Progress Bar Methods
219223
~~~~~~~~~~~~~~~~~~~~
220224

@@ -259,6 +263,8 @@ Progress Bar Methods
259263
Creates an instance of :class:`Symfony\\Component\\Console\\Helper\\ProgressBar`
260264
styled according to the Symfony Style Guide.
261265

266+
.. _symfony-style-questions:
267+
262268
User Input Methods
263269
~~~~~~~~~~~~~~~~~~
264270

@@ -331,6 +337,8 @@ User Input Methods
331337

332338
The ``multiSelect`` option of ``choice()`` was introduced in Symfony 6.2.
333339

340+
.. _symfony-style-blocks:
341+
334342
Result Methods
335343
~~~~~~~~~~~~~~
336344

0 commit comments

Comments
 (0)