/**
  * Make a new Subcommand
  *
  * @param string|array $name The long name of the subcommand, or an array with all the properties.
  * @param string $help The help text for this option.
  * @param \Cake\Console\ConsoleOptionParser|array|null $parser A parser for this subcommand. Either a ConsoleOptionParser, or an
  *   array that can be used with ConsoleOptionParser::buildFromArray().
  */
 public function __construct($name, $help = '', $parser = null)
 {
     if (is_array($name) && isset($name['name'])) {
         foreach ($name as $key => $value) {
             $this->{'_' . $key} = $value;
         }
     } else {
         $this->_name = $name;
         $this->_help = $help;
         $this->_parser = $parser;
     }
     if (is_array($this->_parser)) {
         $this->_parser['command'] = $this->_name;
         $this->_parser = ConsoleOptionParser::buildFromArray($this->_parser);
     }
 }
 /**
  * Tests toArray()
  *
  * @return void
  */
 public function testToArray()
 {
     $spec = ['command' => 'test', 'arguments' => ['name' => ['help' => 'The name'], 'other' => ['help' => 'The other arg']], 'options' => ['name' => ['help' => 'The name'], 'other' => ['help' => 'The other arg']], 'subcommands' => ['initdb' => ['help' => 'make database']], 'description' => 'description text', 'epilog' => 'epilog text'];
     $parser = ConsoleOptionParser::buildFromArray($spec);
     $result = $parser->toArray();
     $this->assertEquals($spec['description'], $result['description']);
     $this->assertEquals($spec['epilog'], $result['epilog']);
     $options = $result['options'];
     $this->assertTrue(isset($options['name']));
     $this->assertTrue(isset($options['other']));
     $this->assertEquals(2, count($result['arguments']));
     $this->assertEquals(1, count($result['subcommands']));
 }
 /**
  * test building a parser from an array.
  *
  * @return void
  */
 public function testBuildFromArray()
 {
     $spec = array('command' => 'test', 'arguments' => array('name' => array('help' => 'The name'), 'other' => array('help' => 'The other arg')), 'options' => array('name' => array('help' => 'The name'), 'other' => array('help' => 'The other arg')), 'subcommands' => array('initdb' => array('help' => 'make database')), 'description' => 'description text', 'epilog' => 'epilog text');
     $parser = ConsoleOptionParser::buildFromArray($spec);
     $this->assertEquals($spec['description'], $parser->description());
     $this->assertEquals($spec['epilog'], $parser->epilog());
     $options = $parser->options();
     $this->assertTrue(isset($options['name']));
     $this->assertTrue(isset($options['other']));
     $args = $parser->arguments();
     $this->assertEquals(2, count($args));
     $commands = $parser->subcommands();
     $this->assertEquals(1, count($commands));
 }