Browse Source

Adds `sort` switch to optionally sort route names A-Z, default is none

chris cnizzardini 5 years ago
parent
commit
4c3fc0a0ab
2 changed files with 10 additions and 4 deletions
  1. 9 3
      src/Command/RoutesCommand.php
  2. 1 1
      tests/TestCase/Command/RoutesCommandTest.php

+ 9 - 3
src/Command/RoutesCommand.php

@@ -66,9 +66,11 @@ class RoutesCommand extends Command
             $output[] = $item;
         }
 
-        usort($output, function ($a, $b) {
-            return strcasecmp($a[0], $b[0]);
-        });
+        if ($args->getOption('sort') !== null) {
+            usort($output, function ($a, $b) {
+                return strcasecmp($a[0], $b[0]);
+            });
+        }
 
         array_unshift($output, $header);
 
@@ -91,6 +93,10 @@ class RoutesCommand extends Command
             ->addOption('verbose', [
                 'help' => 'Display verbose output',
                 'short' => 'v',
+            ])
+            ->addOption('sort', [
+                'help' => 'Sorts alphabetically by route name A-Z',
+                'short' => 's',
             ]);
 
         return $parser;

+ 1 - 1
tests/TestCase/Command/RoutesCommandTest.php

@@ -71,7 +71,7 @@ class RoutesCommandTest extends TestCase
      */
     public function testRouteList()
     {
-        $this->exec('routes -v');
+        $this->exec('routes -v -s');
         $this->assertExitCode(Command::CODE_SUCCESS);
         $this->assertOutputContainsRow([
             '<info>Route name</info>',