|
| 1 | +.. index:: |
| 2 | + single: Console; Usage |
| 3 | + |
| 4 | +Console Usage |
| 5 | +============= |
| 6 | + |
| 7 | +As well as the options you specify for the commands you add there are some |
| 8 | +built options as well as a couple of built in commands for the console component. |
| 9 | + |
| 10 | +.. note:: |
| 11 | + These examples assume you have added a file ``app/console`` to run at |
| 12 | + the cli:: |
| 13 | + |
| 14 | + #!/usr/bin/env php |
| 15 | + # app/console |
| 16 | + <?php |
| 17 | + |
| 18 | + use Symfony\Component\Console\Application; |
| 19 | + |
| 20 | + $application = new Application(); |
| 21 | + // ... |
| 22 | + $application->run(); |
| 23 | + |
| 24 | +Built in Commands |
| 25 | +~~~~~~~~~~~~~~~~~ |
| 26 | + |
| 27 | +There is a built in command ``list`` which outputs all the standard options |
| 28 | +and the registered commands: |
| 29 | + |
| 30 | +.. code-block:: bash |
| 31 | +
|
| 32 | + $ php app/console list |
| 33 | +
|
| 34 | +You can get the same output by not running any command as well |
| 35 | + |
| 36 | +.. code-block:: bash |
| 37 | +
|
| 38 | + $ php app/console |
| 39 | +
|
| 40 | +The help command lists the help information for the specified command. For |
| 41 | +example, to get the help for the ``list`` command: |
| 42 | + |
| 43 | +.. code-block:: bash |
| 44 | +
|
| 45 | + $ php app/console help list |
| 46 | +
|
| 47 | +Running ``help`` without specifying a command will list the global options: |
| 48 | + |
| 49 | +.. code-block:: bash |
| 50 | +
|
| 51 | + $ php app/console help |
| 52 | +
|
| 53 | +Global Options |
| 54 | +~~~~~~~~~~~~~~ |
| 55 | + |
| 56 | +You can get help information for any command with the ``--help`` option, to |
| 57 | +get help for the list command: |
| 58 | + |
| 59 | +.. code-block:: bash |
| 60 | +
|
| 61 | + $ php app/console list --help |
| 62 | + $ php app/console list -h |
| 63 | +
|
| 64 | +You can suppress output with: |
| 65 | + |
| 66 | +.. code-block:: bash |
| 67 | +
|
| 68 | + $ php app/console list --quiet |
| 69 | + $ php app/console list -q |
| 70 | +
|
| 71 | +You can get more verbose messages (where this is supported for a command) |
| 72 | +with: |
| 73 | + |
| 74 | +.. code-block:: bash |
| 75 | +
|
| 76 | + $ php app/console list -verbose |
| 77 | + $ php app/console list -v |
| 78 | +
|
| 79 | +If you set the optional arguments to give your application a name and version:: |
| 80 | + |
| 81 | + $application = new Application('Acme Console Application', '1.2'); |
| 82 | + |
| 83 | +then you can use: |
| 84 | + |
| 85 | +.. code-block:: bash |
| 86 | +
|
| 87 | + $ php app/console list -version |
| 88 | + $ php app/console list -V |
| 89 | +
|
| 90 | +to get this information output: |
| 91 | + |
| 92 | +.. code-block:: text |
| 93 | +
|
| 94 | + Acme Console Application version 1.2 |
| 95 | +
|
| 96 | +If you do not provide both arguments then it will just output: |
| 97 | + |
| 98 | +.. code-block:: text |
| 99 | +
|
| 100 | + console tool |
| 101 | +
|
| 102 | +You can force turning on ANSI output coloring with: |
| 103 | + |
| 104 | +.. code-block:: bash |
| 105 | +
|
| 106 | + $ php app/console list --ansi |
| 107 | +
|
| 108 | +or turn it off with: |
| 109 | + |
| 110 | +.. code-block:: bash |
| 111 | +
|
| 112 | + $ php app/console list --no-ansi |
| 113 | +
|
| 114 | +You can suppress any interactive questions from the command you are running with: |
| 115 | + |
| 116 | +.. code-block:: bash |
| 117 | +
|
| 118 | + $ php app/console list --no-interaction |
| 119 | + $ php app/console list -n |
| 120 | +
|
| 121 | +Shortcut Syntax |
| 122 | +~~~~~~~~~~~~~~~ |
| 123 | + |
| 124 | +You do not have to type out the full command names. You can just type the |
| 125 | +shortest unambiguous name to run a command. So if there are non clashing |
| 126 | +commands, then you can run ``help`` like this: |
| 127 | + |
| 128 | +.. code-block:: bash |
| 129 | +
|
| 130 | + $ php app/console h |
| 131 | +
|
| 132 | +If you have commands using ``:`` to namespace commands then you just have |
| 133 | +to type the shortest unambiguous text for each part. If you have created the |
| 134 | +``demo:greet`` as shown in :doc:`/components/console/introduction` then you |
| 135 | +can run it with: |
| 136 | + |
| 137 | +.. code-block:: bash |
| 138 | +
|
| 139 | + $ php app/console d:g Fabien |
| 140 | +
|
| 141 | +If you choose too short a command so it is ambiguous then no command will be run and |
| 142 | +some suggestions of the possible commands to choose from will be output. |
0 commit comments