Skip to content

Commit a58dccf

Browse files
committed
Reword
1 parent e38e45b commit a58dccf

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

console/input.rst

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,29 +314,34 @@ The above code can be simplified as follows because ``false !== null``::
314314
Fetching The Raw Command Input
315315
------------------------------
316316

317-
Sometimes, you may need to fetch the raw input that was passed to the command.
318-
This is useful when you need to parse the input yourself or when you need to
319-
pass the input to another command without having to worry about the number
320-
of arguments or options defined in your own command. This can be achieved
321-
thanks to the
322-
:method:`Symfony\\Component\\Console\\Input\\ArgvInput::getRawTokens` method::
317+
Symfony provides a :method:`Symfony\\Component\\Console\\Input\\ArgvInput::getRawTokens`
318+
method to fetch the raw input that was passed to the command. This is useful if
319+
you want to parse the input yourself or when you need to pass the input to another
320+
command without having to worry about the number of arguments or options::
323321

324322
// ...
325323
use Symfony\Component\Process\Process;
326324

327325
protected function execute(InputInterface $input, OutputInterface $output): int
328326
{
329-
// pass the raw input of your command to the "ls" command
330-
$process = new Process(['ls', ...$input->getRawTokens(true)]);
327+
// if this command was run as:
328+
// php bin/console app:my-command foo --bar --baz=3 --qux=value1 --qux=value2
329+
330+
$tokens = $input->getRawTokens();
331+
// $tokens = ['app:my-command', 'foo', '--bar', '--baz=3', '--qux=value1', '--qux=value2'];
332+
333+
// pass true as argument to not include the original command name
334+
$tokens = $input->getRawTokens(true);
335+
// $tokens = ['foo', '--bar', '--baz=3', '--qux=value1', '--qux=value2'];
336+
337+
// pass the raw input to any other command (from Symfony or the operating system)
338+
$process = new Process(['app:other-command', ...$input->getRawTokens(true)]);
331339
$process->setTty(true);
332340
$process->mustRun();
333341

334342
// ...
335343
}
336344

337-
You can include the current command name in the raw tokens by passing ``true``
338-
to the ``getRawTokens`` method only parameter.
339-
340345
.. versionadded:: 7.1
341346

342347
The :method:`Symfony\\Component\\Console\\Input\\ArgvInput::getRawTokens`

0 commit comments

Comments
 (0)