Skip to content

Commit

Permalink
minor #5425 Added a caution note about invoking other commands (kix, …
Browse files Browse the repository at this point in the history
…javiereguiluz)

This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #5425).

Discussion
----------

Added a caution note about invoking other commands

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes
| Applies to    | all
| Fixed tickets | -

This PR finishes #4493. That's why is committed against `master` branch, but it should be merged in 2.3+.

Commits
-------

2c491be Fixed typos
b86ffb6 Removed duplication and moved a caution message
57938a5 [Console] Added a cookbook entry on invoking other commands
  • Loading branch information
weaverryan committed Jul 7, 2015
2 parents eb1ee92 + 2c491be commit 7d1f764
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
23 changes: 18 additions & 5 deletions components/console/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ method::
You can also test a whole console application by using
:class:`Symfony\\Component\\Console\\Tester\\ApplicationTester`.

.. _calling-existing-command:

Calling an Existing Command
---------------------------

Expand Down Expand Up @@ -478,16 +480,27 @@ Calling a command from another one is straightforward::
}

First, you :method:`Symfony\\Component\\Console\\Application::find` the
command you want to execute by passing the command name.

Then, you need to create a new
:class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the arguments and
options you want to pass to the command.
command you want to execute by passing the command name. Then, you need to create
a new :class:`Symfony\\Component\\Console\\Input\\ArrayInput` with the arguments
and options you want to pass to the command.

Eventually, calling the ``run()`` method actually executes the command and
returns the returned code from the command (return value from command's
``execute()`` method).

.. tip::

If you want to suppress the output of the executed command, pass a
:class:`Symfony\\Component\\Console\\Output\\NullOutput` as the second
argument to ``$command->execute()``.

.. caution::

Note that all the commands will run in the same process and some of Symfony's
built-in commands may not work well this way. For instance, the ``cache:clear``
and ``cache:warmup`` commands change some class definitions, so running
something after them is likely to break.

.. note::

Most of the time, calling a command from code that is not executed on the
Expand Down
6 changes: 6 additions & 0 deletions cookbook/console/console_command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ before translating contents::
However for other services the solution might be more complex. For more details,
see :doc:`/cookbook/service_container/scopes`.

Invoking other Commands
-----------------------

See :ref:`calling-existing-command` if you need to implement a command that runs
other dependent commands.

Testing Commands
----------------

Expand Down

0 comments on commit 7d1f764

Please sign in to comment.