Skip to content

Commit 01b6dc6

Browse files
ENH Add backwards-compatible aliases for "sake dev" and "sake dev/tasks" (#11649)
1 parent 26ce438 commit 01b6dc6

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/Cli/Command/TasksCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Note the description is blue so it stands out, to avoid developers missing it if they add a new
2121
* task and suddenly they don't see the tasks in their main commands list anymore.
2222
*/
23-
#[AsCommand(name: 'tasks', description: '<fg=blue>See a list of build tasks to run</>')]
23+
#[AsCommand(name: 'tasks', description: '<fg=blue>See a list of build tasks to run</>', aliases: ['dev/tasks'])]
2424
class TasksCommand extends Command
2525
{
2626
private Command $listCommand;

src/Cli/Sake.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
185185
$suggestions->suggestValue(new Suggestion($command->getName(), $command->getDescription()));
186186
foreach ($command->getAliases() as $name) {
187187
// Skip legacy dev aliases
188-
if (str_starts_with($name, 'dev/')) {
188+
if ($name === 'dev' || str_starts_with($name, 'dev/')) {
189189
continue;
190190
}
191191
$suggestions->suggestValue(new Suggestion($name, $command->getDescription()));
@@ -204,7 +204,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
204204
{
205205
$name = $command->getName() ?? '';
206206
$nameUsedAs = $input->getFirstArgument() ?? '';
207-
if (str_starts_with($nameUsedAs, 'dev/')) {
207+
if ($nameUsedAs === 'dev' || str_starts_with($nameUsedAs, 'dev/')) {
208208
Deprecation::notice(
209209
'6.0.0',
210210
"Using the command with the name '$nameUsedAs' is deprecated. Use '$name' instead",
@@ -243,6 +243,10 @@ protected function getDefaultCommands(): array
243243
if (in_array(get_class($command), $toHide)) {
244244
$command->setHidden(true);
245245
}
246+
// Add deprecated alias "sake dev" for backwards compatibility
247+
if ($command instanceof ListCommand) {
248+
$command->setAliases([...$command->getAliases(), 'dev']);
249+
}
246250
}
247251

248252
$commands[] = $this->createFlushCommand();

tests/php/Cli/SakeTest.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,23 +248,42 @@ public function testVersion(): void
248248
$this->assertSame($versionProvider->getVersion(), $sake->getVersion());
249249
}
250250

251-
public function testLegacyDevCommands(): void
251+
public static function provideLegacyDevCommands(): array
252+
{
253+
return [
254+
[
255+
'command' => 'dev',
256+
'correctName' => 'list',
257+
],
258+
[
259+
'command' => 'dev/config',
260+
'correctName' => 'config:dump',
261+
],
262+
[
263+
'command' => 'dev/tasks',
264+
'correctName' => 'tasks',
265+
],
266+
// NOTE: Do not run `dev/build` as that will manipulate the database in a way that causes subsequent tests to fail.
267+
];
268+
}
269+
270+
#[DataProvider('provideLegacyDevCommands')]
271+
public function testLegacyDevCommands(string $command, string $correctName): void
252272
{
253273
$sake = new Sake(Injector::inst()->get(Kernel::class));
254274
$sake->setAutoExit(false);
255-
$input = new ArrayInput(['dev/config']);
275+
$input = new ArrayInput([$command, '--quiet' => 1]);
256276
$input->setInteractive(false);
257277
$output = new BufferedOutput();
258278

259279
$deprecationsWereEnabled = Deprecation::isEnabled();
260280
Deprecation::enable();
261281
$this->expectException(DeprecationTestException::class);
262-
$expectedErrorString = 'Using the command with the name \'dev/config\' is deprecated. Use \'config:dump\' instead';
282+
$expectedErrorString = "Using the command with the name '$command' is deprecated. Use '$correctName' instead";
263283
$this->expectExceptionMessage($expectedErrorString);
264284

265285
$exitCode = $sake->run($input, $output);
266286
$this->assertSame(0, $exitCode, 'command should run successfully');
267-
// $this->assertStringContainsString('abababa', $output->fetch());
268287

269288
$this->allowCatchingDeprecations($expectedErrorString);
270289
try {

0 commit comments

Comments
 (0)