Browse Source

Add way to get argument names as a list.

This is necessary to make Cake\Console\Arguments work.
Mark Story 8 years ago
parent
commit
a57945d9cd

+ 15 - 0
src/Console/ConsoleOptionParser.php

@@ -643,6 +643,21 @@ class ConsoleOptionParser
     }
 
     /**
+     * Get the list of argument names.
+     *
+     * @return string[]
+     */
+    public function argumentNames()
+    {
+        $out = [];
+        foreach ($this->_args as $arg) {
+            $out[] = $arg->name();
+        }
+
+        return $out;
+    }
+
+    /**
      * Get the defined options in the parser.
      *
      * @return array

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

@@ -467,6 +467,10 @@ class ConsoleOptionParserTest extends TestCase
         $this->assertEquals('name', $result[1]->name());
         $this->assertEquals('bag', $result[2]->name());
         $this->assertSame([0, 1, 2], array_keys($result));
+        $this->assertEquals(
+            ['other', 'name', 'bag'],
+            $parser->argumentNames()
+        );
     }
 
     /**