Skip to content

Commit

Permalink
minor #19713 [Console] Mention ArgvInput::getRawTokens (alexandre-d…
Browse files Browse the repository at this point in the history
…aubois)

This PR was merged into the 7.1 branch.

Discussion
----------

[Console] Mention `ArgvInput::getRawTokens`

Fix #19693, #19673

Commits
-------

7afdaa3 [Console] Mention `ArgvInput::getRawTokens`
  • Loading branch information
javiereguiluz committed Apr 15, 2024
2 parents 7b591e0 + 7afdaa3 commit e38e45b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions console/input.rst
Expand Up @@ -311,6 +311,37 @@ The above code can be simplified as follows because ``false !== null``::
$yell = ($optionValue !== false);
$yellLouder = ($optionValue === 'louder');

Fetching The Raw Command Input
------------------------------

Sometimes, you may need to fetch the raw input that was passed to the command.
This is useful when you need to parse the input yourself or when you need to
pass the input to another command without having to worry about the number
of arguments or options defined in your own command. This can be achieved
thanks to the
:method:`Symfony\\Component\\Console\\Input\\ArgvInput::getRawTokens` method::

// ...
use Symfony\Component\Process\Process;

protected function execute(InputInterface $input, OutputInterface $output): int
{
// pass the raw input of your command to the "ls" command
$process = new Process(['ls', ...$input->getRawTokens(true)]);
$process->setTty(true);
$process->mustRun();

// ...
}

You can include the current command name in the raw tokens by passing ``true``
to the ``getRawTokens`` method only parameter.

.. versionadded:: 7.1

The :method:`Symfony\\Component\\Console\\Input\\ArgvInput::getRawTokens`
method was introduced in Symfony 7.1.

Adding Argument/Option Value Completion
---------------------------------------

Expand Down

0 comments on commit e38e45b

Please sign in to comment.