Skip to content

Commit 1878694

Browse files
committed
Document input definition completion and Fish support
1 parent d2f1536 commit 1878694

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

Diff for: console.rst

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ command, for instance:
5959
Console Completion
6060
~~~~~~~~~~~~~~~~~~
6161

62+
.. versionadded:: 6.1
63+
64+
Console completion for Fish was introduced in Symfony 6.1.
65+
6266
If you are using the Bash shell, you can install Symfony's completion
6367
script to get auto completion when typing commands in the terminal. All
6468
commands support name and option completion, and some can even complete

Diff for: console/input.rst

+29-18
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ can also implement value completion for the input in your commands. For
313313
instance, you may want to complete all usernames from the database in the
314314
``name`` argument of your greet command.
315315

316-
To achieve this, override the ``complete()`` method in the command::
316+
To achieve this, use the 5th argument of ``addArgument()``/``addOption``::
317317

318318
// ...
319319
use Symfony\Component\Console\Completion\CompletionInput;
@@ -322,32 +322,43 @@ To achieve this, override the ``complete()`` method in the command::
322322
class GreetCommand extends Command
323323
{
324324
// ...
325-
326-
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
325+
protected function configure(): void
327326
{
328-
if ($input->mustSuggestArgumentValuesFor('names')) {
329-
// the user asks for completion input for the "names" option
330-
331-
// the value the user already typed, e.g. when typing "app:greet Fa" before
332-
// pressing Tab, this will contain "Fa"
333-
$currentValue = $input->getCompletionValue();
334-
335-
// get the list of username names from somewhere (e.g. the database)
336-
// you may use $currentValue to filter down the names
337-
$availableUsernames = ...;
338-
339-
// then add the retrieved names as suggested values
340-
$suggestions->suggestValues($availableUsernames);
341-
}
327+
$this
328+
->addArgument(
329+
'names',
330+
InputArgument::IS_ARRAY,
331+
'Who do you want to greet (separate multiple names with a space)?',
332+
null,
333+
function (CompletionInput $input) {
334+
// the value the user already typed, e.g. when typing "app:greet Fa" before
335+
// pressing Tab, this will contain "Fa"
336+
$currentValue = $input->getCompletionValue();
337+
338+
// get the list of username names from somewhere (e.g. the database)
339+
// you may use $currentValue to filter down the names
340+
$availableUsernames = ...;
341+
342+
// then suggested the usernames as values
343+
return $availableUsernames;
344+
}
345+
)
346+
;
342347
}
343348
}
344349

350+
.. versionadded:: 6.1
351+
352+
The argument to ``addOption()``/``addArgument()`` was introduced in
353+
Symfony 6.1. Prior to this version, you had to override the
354+
``complete()`` method of the command.
355+
345356
That's all you need! Assuming users "Fabien" and "Fabrice" exist, pressing
346357
tab after typing ``app:greet Fa`` will give you these names as a suggestion.
347358

348359
.. tip::
349360

350-
The bash shell is able to handle huge amounts of suggestions and will
361+
The shell script is able to handle huge amounts of suggestions and will
351362
automatically filter the suggested values based on the existing input
352363
from the user. You do not have to implement any filter logic in the
353364
command.

Diff for: page_creation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ You'll learn about many more commands as you continue!
197197

198198
.. tip::
199199

200-
If you are using the Bash shell, you can set up completion support.
200+
If you are using the Bash or Fish shell, you can set up completion support.
201201
This autocompletes commands and other input when using ``bin/console``.
202202
See :ref:`the Console document <console-completion-setup>` for more
203203
information on how to set up completion.

0 commit comments

Comments
 (0)