예제 #1
0
 public static function formatOptions(nbOptionSet $optionSet, $max)
 {
     $options = $optionSet->getOptions();
     if (count($options) == 0) {
         return '';
     }
     $res = "\n";
     $res .= self::format("Options:", nbLogger::COMMENT) . "\n";
     foreach ($options as $option) {
         $res .= self::format(sprintf(" --%-{$max}s  ", $option->getName()), nbLogger::INFO);
         $res .= self::format($option->hasShortcut() ? '-' . $option->getShortcut() : '  ', nbLogger::INFO);
         $res .= ' ' . $option->getDescription();
         if ($option->hasOptionalParameter() && !$option->isArray()) {
             $res .= self::format(' (default: ' . $option->getValue() . ')', nbLogger::COMMENT);
         }
         $res .= "\n";
     }
     return $res;
 }
예제 #2
0
$set = new nbOptionSet(array($foo));
$t->is($set->count(), 1, '->__construct() has 1 option');
$t->is($set->countRequired(), 0, '->__contruct() has no required options');
$t->is($set->hasOption('foo'), true, '->__construct() built a set with option "foo"');
// ->addOptions()
$t->comment('nbOptionSetTest - Test add options array');
$set = new nbOptionSet();
$set->addOptions(array($foo, $bar));
$t->is($set->getOptions(), array('foo' => $foo, 'bar' => $bar), '->addOptions() added an array of options');
$set->addOptions(array($bas));
$t->is($set->getOptions(), array('foo' => $foo, 'bar' => $bar, 'bas' => $bas), '->addOptions() does not clear previous options');
// ->addOption()
$t->comment('nbOptionSetTest - Test add option');
$set = new nbOptionSet();
$set->addOption($foo);
$t->is($set->getOptions(), array('foo' => $foo), '->addOption() added option "foo"');
try {
    $set->addOption($foo);
    $t->fail('->addOption() throws an InvalidOptionException if an option with the same name is added');
} catch (InvalidArgumentException $e) {
    $t->pass('->addOption() throws an InvalidOptionException if an option with the same name is added');
}
// ->getOption()
$t->comment('nbOptionSetTest - Test get option');
$set = new nbOptionSet(array($foo));
$t->is($set->getOption('foo'), $foo, '->getOption() returns an nbOption by its name');
try {
    $set->getOption('bar');
    $t->fail('->getOption() throws a RangeException exception if the option name does not exist');
} catch (RangeException $e) {
    $t->pass('->getOption() throws a RangeException exception if the option name does not exist');