Skip to content

Navigation Menu

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

[Console] Allow to return all tokens after the command name #54347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions 23 src/Symfony/Component/Console/Input/ArgvInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,30 @@ public function getParameterOption(string|array $values, string|bool|int|float|a
/**
* Returns un-parsed and not validated tokens.
*
* @param bool $strip Whether to return the raw parameters (false) or the values after the command name (true)
*
* @return list<string>
*/
public function getRawTokens(): array
public function getRawTokens(bool $strip = false): array
{
return $this->tokens;
if (!$strip) {
return $this->tokens;
}

$parameters = [];
$keep = false;
foreach ($this->tokens as $value) {
if (!$keep && $value === $this->getFirstArgument()) {
$keep = true;

continue;
}
if ($keep) {
$parameters[] = $value;
}
}

return $parameters;
}

/**
Expand Down
27 changes: 27 additions & 0 deletions 27 src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,31 @@ public function testParseOptionWithValueOptionalGivenEmptyAndOptionalArgument()
$this->assertEquals(['foo' => '0'], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses optional arguments');
}

public function testGetRawTokensFalse()
{
$input = new ArgvInput(['cli.php', '--foo', 'bar']);
$this->assertSame(['--foo', 'bar'], $input->getRawTokens());
}

/**
* @dataProvider provideGetRawTokensTrueTests
*/
public function testGetRawTokensTrue(array $argv, array $expected)
{
$input = new ArgvInput($argv);
$this->assertSame($expected, $input->getRawTokens(true));
}

public static function provideGetRawTokensTrueTests(): iterable
{
yield [['app/console', 'foo:bar'], []];
yield [['app/console', 'foo:bar', '--env=prod'], ['--env=prod']];
yield [['app/console', 'foo:bar', '--env', 'prod'], ['--env', 'prod']];
yield [['app/console', '--no-ansi', 'foo:bar', '--env', 'prod'], ['--env', 'prod']];
yield [['app/console', '--no-ansi', 'foo:bar', '--env', 'prod'], ['--env', 'prod']];
yield [['app/console', '--no-ansi', 'foo:bar', 'argument'], ['argument']];
yield [['app/console', '--no-ansi', 'foo:bar', 'foo:bar'], ['foo:bar']];
yield [['app/console', '--no-ansi', 'foo:bar', '--', 'argument'], ['--', 'argument']];
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.