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

Commit 76ab38f

Browse filesBrowse files
committed
feature #60344 [Console] Use kebab-case for auto-guessed input arguments/options names (chalasr)
This PR was merged into the 7.3 branch. Discussion ---------- [Console] Use kebab-case for auto-guessed input arguments/options names | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT As it is standard for console options/arguments to be named using kebab-case, I propose to map the invoke parameter names using their kebab-case form in the input definition when they are initially camelCased or snake_cased. Commits ------- 84c0e5b [Console] Use kebab-case for auto-guessed input arguments/options names
2 parents 2b9f361 + 84c0e5b commit 76ab38f
Copy full SHA for 76ab38f

File tree

4 files changed

+12
-10
lines changed
Filter options

4 files changed

+12
-10
lines changed

‎src/Symfony/Component/Console/Attribute/Argument.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Attribute/Argument.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Exception\LogicException;
1717
use Symfony\Component\Console\Input\InputArgument;
1818
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\String\UnicodeString;
1920

2021
#[\Attribute(\Attribute::TARGET_PARAMETER)]
2122
class Argument
@@ -65,7 +66,7 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self
6566
}
6667

6768
if (!$self->name) {
68-
$self->name = $name;
69+
$self->name = (new UnicodeString($name))->kebab();
6970
}
7071

7172
$self->default = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null;

‎src/Symfony/Component/Console/Attribute/Option.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Attribute/Option.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Exception\LogicException;
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Input\InputOption;
19+
use Symfony\Component\String\UnicodeString;
1920

2021
#[\Attribute(\Attribute::TARGET_PARAMETER)]
2122
class Option
@@ -73,7 +74,7 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self
7374
}
7475

7576
if (!$self->name) {
76-
$self->name = $name;
77+
$self->name = (new UnicodeString($name))->kebab();
7778
}
7879

7980
$self->default = $parameter->getDefaultValue();

‎src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Command/InvokableCommandTest.php
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testCommandInputArgumentDefinition()
2929
{
3030
$command = new Command('foo');
3131
$command->setCode(function (
32-
#[Argument(name: 'first-name')] string $name,
32+
#[Argument(name: 'very-first-name')] string $name,
3333
#[Argument] ?string $firstName,
3434
#[Argument] string $lastName = '',
3535
#[Argument(description: 'Short argument description')] string $bio = '',
@@ -38,17 +38,17 @@ public function testCommandInputArgumentDefinition()
3838
return 0;
3939
});
4040

41-
$nameInputArgument = $command->getDefinition()->getArgument('first-name');
42-
self::assertSame('first-name', $nameInputArgument->getName());
41+
$nameInputArgument = $command->getDefinition()->getArgument('very-first-name');
42+
self::assertSame('very-first-name', $nameInputArgument->getName());
4343
self::assertTrue($nameInputArgument->isRequired());
4444

45-
$lastNameInputArgument = $command->getDefinition()->getArgument('firstName');
46-
self::assertSame('firstName', $lastNameInputArgument->getName());
45+
$lastNameInputArgument = $command->getDefinition()->getArgument('first-name');
46+
self::assertSame('first-name', $lastNameInputArgument->getName());
4747
self::assertFalse($lastNameInputArgument->isRequired());
4848
self::assertNull($lastNameInputArgument->getDefault());
4949

50-
$lastNameInputArgument = $command->getDefinition()->getArgument('lastName');
51-
self::assertSame('lastName', $lastNameInputArgument->getName());
50+
$lastNameInputArgument = $command->getDefinition()->getArgument('last-name');
51+
self::assertSame('last-name', $lastNameInputArgument->getName());
5252
self::assertFalse($lastNameInputArgument->isRequired());
5353
self::assertSame('', $lastNameInputArgument->getDefault());
5454

‎src/Symfony/Component/Console/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/deprecation-contracts": "^2.5|^3",
2121
"symfony/polyfill-mbstring": "~1.0",
2222
"symfony/service-contracts": "^2.5|^3",
23-
"symfony/string": "^6.4|^7.0"
23+
"symfony/string": "^7.2"
2424
},
2525
"require-dev": {
2626
"symfony/config": "^6.4|^7.0",

0 commit comments

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