Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5d24503

Browse filesBrowse files
committed
[Console] Allow to returns all tokens after the command name
1 parent a9133af commit 5d24503
Copy full SHA for 5d24503

File tree

2 files changed

+47
-2
lines changed
Filter options

2 files changed

+47
-2
lines changed

‎src/Symfony/Component/Console/Input/ArgvInput.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/ArgvInput.php
+21-2Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,30 @@ public function getParameterOption(string|array $values, string|bool|int|float|a
348348
/**
349349
* Returns un-parsed and not validated tokens.
350350
*
351+
* @param bool $strip Whether to return the raw parameters (false) or the values after the command name (true)
352+
*
351353
* @return list<string>
352354
*/
353-
public function getRawTokens(): array
355+
public function getRawTokens(bool $strip = false): array
354356
{
355-
return $this->tokens;
357+
if (!$strip) {
358+
return $this->tokens;
359+
}
360+
361+
$parameters = [];
362+
$keep = false;
363+
foreach ($this->tokens as $value) {
364+
if ($value === $this->getFirstArgument()) {
365+
$keep = true;
366+
367+
continue;
368+
}
369+
if ($keep) {
370+
$parameters[] = $value;
371+
}
372+
}
373+
374+
return $parameters;
356375
}
357376

358377
/**

‎src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,4 +562,30 @@ public function testParseOptionWithValueOptionalGivenEmptyAndOptionalArgument()
562562
$this->assertEquals(['foo' => '0'], $input->getOptions(), '->parse() parses optional options with empty value as null');
563563
$this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses optional arguments');
564564
}
565+
566+
public function testGetRawTokensFalse()
567+
{
568+
$input = new ArgvInput(['cli.php', '--foo', 'bar']);
569+
$this->assertSame(['--foo', 'bar'], $input->getRawTokens());
570+
}
571+
572+
/**
573+
* @dataProvider provideGetRawTokensTrueTests
574+
*/
575+
public function testGetRawTokensTrue(array $argv, array $expected)
576+
{
577+
$input = new ArgvInput($argv);
578+
$this->assertSame($expected, $input->getRawTokens(true));
579+
}
580+
581+
public static function provideGetRawTokensTrueTests(): iterable
582+
{
583+
yield [['app/console', 'foo:bar'], []];
584+
yield [['app/console', 'foo:bar', '--env=prod'], ['--env=prod']];
585+
yield [['app/console', 'foo:bar', '--env', 'prod'], ['--env', 'prod']];
586+
yield [['app/console', '--no-ansi', 'foo:bar', '--env', 'prod'], ['--env', 'prod']];
587+
yield [['app/console', '--no-ansi', 'foo:bar', '--env', 'prod'], ['--env', 'prod']];
588+
yield [['app/console', '--no-ansi', 'foo:bar', 'argument'], ['argument']];
589+
yield [['app/console', '--no-ansi', 'foo:bar', '--', 'argument'], ['--', 'argument']];
590+
}
565591
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.