Browse Source

Allow camelBacked method names for subcommands.

mscherer 9 years ago
parent
commit
4069d5caff

+ 1 - 0
src/Console/ConsoleOptionParser.php

@@ -576,6 +576,7 @@ class ConsoleOptionParser
             $command = $name;
             $name = $command->name();
         } else {
+            $name = Inflector::underscore($name);
             $defaults = [
                 'name' => $name,
                 'help' => '',

+ 16 - 0
tests/TestCase/Console/ConsoleOptionParserTest.php

@@ -592,6 +592,22 @@ class ConsoleOptionParserTest extends TestCase
     }
 
     /**
+     * Tests setting a subcommand up for a Shell method `initMyDb`.
+     *
+     * @return void
+     */
+    public function testSubcommandCamelBacked()
+    {
+        $parser = new ConsoleOptionParser('test', false);
+        $result = $parser->addSubcommand('initMyDb', [
+            'help' => 'Initialize the database'
+        ]);
+
+        $subcommands = array_keys($result->subcommands());
+        $this->assertEquals(['init_my_db'], $subcommands, 'Adding a subcommand does not work with camel backed method names.');
+    }
+
+    /**
      * Test addSubcommand inherits options as no
      * parser is created.
      *