Skip to content

Commit f519ca6

Browse files
committed
refactor: rename -h option of routes command as --handler
1 parent 2010172 commit f519ca6

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

system/Commands/Utilities/Routes.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,26 @@ class Routes extends BaseCommand
7373
* @var array<string, string>
7474
*/
7575
protected $options = [
76-
'-h' => 'Sort by Handler.',
77-
'--host' => 'Specify hostname in request URI.',
76+
'--handler' => 'Sort by Handler.',
77+
'--host' => 'Specify hostname in request URI.',
7878
];
7979

8080
/**
8181
* Displays the help for the spark cli script itself.
8282
*/
8383
public function run(array $params)
8484
{
85-
$sortByHandler = array_key_exists('h', $params);
86-
$host = $params['host'] ?? null;
85+
$sortByHandler = array_key_exists('handler', $params);
86+
87+
if (! $sortByHandler && array_key_exists('h', $params)) {
88+
// Support -h as a shortcut but print a warning that it is not the intended use of -h.
89+
CLI::write('Warning: -h will be used as shortcut for --help in v4.8.0. Please use --handler to sort by handler.', 'yellow');
90+
CLI::newLine();
91+
92+
$sortByHandler = true;
93+
}
94+
95+
$host = $params['host'] ?? null;
8796

8897
// Set HTTP_HOST
8998
if ($host !== null) {

tests/system/Commands/Utilities/RoutesTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,41 @@ public function testRoutesCommandSortByHandler(): void
9494
{
9595
Services::injectMock('routes', null);
9696

97+
command('routes --handler');
98+
99+
$expected = <<<'EOL'
100+
+---------+---------+---------------+----------------------------------------+----------------+---------------+
101+
| Method | Route | Name | Handler ↓ | Before Filters | After Filters |
102+
+---------+---------+---------------+----------------------------------------+----------------+---------------+
103+
| GET | closure | » | (Closure) | | |
104+
| GET | / | » | \App\Controllers\Home::index | | |
105+
| GET | testing | testing-index | \App\Controllers\TestController::index | | |
106+
| HEAD | testing | testing-index | \App\Controllers\TestController::index | | |
107+
| POST | testing | testing-index | \App\Controllers\TestController::index | | |
108+
| PATCH | testing | testing-index | \App\Controllers\TestController::index | | |
109+
| PUT | testing | testing-index | \App\Controllers\TestController::index | | |
110+
| DELETE | testing | testing-index | \App\Controllers\TestController::index | | |
111+
| OPTIONS | testing | testing-index | \App\Controllers\TestController::index | | |
112+
| TRACE | testing | testing-index | \App\Controllers\TestController::index | | |
113+
| CONNECT | testing | testing-index | \App\Controllers\TestController::index | | |
114+
| CLI | testing | testing-index | \App\Controllers\TestController::index | | |
115+
+---------+---------+---------------+----------------------------------------+----------------+---------------+
116+
EOL;
117+
$this->assertStringContainsString($expected, $this->getBuffer());
118+
}
119+
120+
/**
121+
* @todo To remove this test and the backward compatibility for -h in v4.8.0.
122+
*/
123+
public function testRoutesCommandSortByHandlerUsingShortcutForBc(): void
124+
{
125+
Services::injectMock('routes', null);
126+
97127
command('routes -h');
98128

99129
$expected = <<<'EOL'
130+
Warning: -h will be used as shortcut for --help in v4.8.0. Please use --handler to sort by handler.
131+
100132
+---------+---------+---------------+----------------------------------------+----------------+---------------+
101133
| Method | Route | Name | Handler ↓ | Before Filters | After Filters |
102134
+---------+---------+---------------+----------------------------------------+----------------+---------------+

user_guide_src/source/changelogs/v4.7.3.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Message Changes
2424
Changes
2525
*******
2626

27+
- **Commands:** The ``-h`` option for the ``routes`` command is renamed to ``--handler`` to avoid conflict with the common use of ``-h`` as a shortcut for ``--help``.
28+
The old ``-h`` option will continue to work until v4.8.0, at which point it will be removed and repurposed as a shortcut for ``--help``.
29+
A warning message is displayed when using the old ``-h`` option to encourage users to switch to the new ``--handler`` option.
30+
2731
************
2832
Deprecations
2933
************

0 commit comments

Comments
 (0)