Exemplo n.º 1
0
 /**
  *
  */
 public function testRegisteredArguments()
 {
     $params = new Parameters();
     $params->registerArgument('testA', 'first test');
     $params->registerArgument('testB', 'second test');
     $args = $params->getRegisteredArguments();
     $expected = array(array('name' => 'testA', 'description' => 'first test'), array('name' => 'testB', 'description' => 'second test'));
     $this->assertEquals($expected, $args);
 }
Exemplo n.º 2
0
 /**
  * Show the help message.
  *
  * @param Parameters $params
  *
  * @return void
  */
 protected function showHelp(Parameters $params)
 {
     $table = new SimpleTable();
     $table->border = false;
     $table->padding = 3;
     $executedFile = basename($params->getExecutedFile());
     $arguments = $params->getRegisteredArguments();
     $argsUsage = '';
     $argsRows = [];
     foreach ($arguments as $arg) {
         $argsUsage .= ' <' . $arg['name'] . '>';
         $argsRows[] = [$arg['name'], $arg['description']];
     }
     $this->outln('Usage: ' . $executedFile . $argsUsage);
     // show possible arguments
     if ($argsRows) {
         $table->addRow([]);
         $table->addRow(['Arguments:']);
         foreach ($argsRows as $row) {
             $table->addRow($row);
         }
     }
     // show possible options
     $options = $params->getRegisteredOptions();
     if ($options) {
         $table->addRow([]);
         $table->addRow(['Options:']);
         foreach ($options as $opt) {
             $val = '';
             switch ($opt['valueFlag']) {
                 case Parameters::VALUE_YES:
                     $val = '=<value>';
                     break;
                 case Parameters::VALUE_OPTIONAL:
                     $val = '[=<value>]';
                     break;
             }
             $def = '--' . $opt['name'] . $val;
             if ($opt['short']) {
                 $def .= ' -' . $opt['short'] . $val;
             }
             $table->addRow([$def, $opt['description']]);
         }
     }
     $this->outln($table->getTable());
 }