Exemplo n.º 1
0
 public function testCanTestForOptionalArguments()
 {
     $name = 'help';
     $desc = 'display this help message';
     $shortSwitch = 'h';
     $obj = new DefinedSwitch($name, $desc);
     $obj->setWithShortSwitch($shortSwitch);
     $this->assertEquals($obj->name, $name);
     $this->assertEquals($obj->desc, $desc);
     $this->assertTrue($obj->testHasShortSwitch($shortSwitch));
     // if we try and test for an arg when none is defined,
     // there should be no error
     $this->assertFalse($obj->testHasArgument());
     $this->assertFalse($obj->testHasOptionalArgument());
     $this->assertFalse($obj->testHasRequiredArgument());
 }
Exemplo n.º 2
0
 public static function showSwitchLongDetails(Context $context, DefinedSwitch $switch)
 {
     $so = $context->stdout;
     $shortOrLongSwitches = $switch->getHumanReadableSwitchList();
     $append = false;
     foreach ($shortOrLongSwitches as $shortOrLongSwitch) {
         if ($append) {
             $so->output(null, ' | ');
         }
         $append = true;
         $so->output($context->switchStyle, $shortOrLongSwitch);
         // is there an argument?
         if ($switch->testHasArgument()) {
             if ($shortOrLongSwitch[1] == '-') {
                 $so->output(null, '=');
             } else {
                 $so->output(null, ' ');
             }
             $so->output($context->argStyle, $switch->arg->name);
         }
     }
     $so->outputLine(null, '');
     $so->addIndent(4);
     $so->outputLine(null, $switch->desc);
     if (isset($switch->longdesc)) {
         $so->outputBlankLine();
         $so->outputLine(null, $switch->longdesc);
     }
     // output the default argument, if it is set
     if ($switch->testHasArgument() && isset($switch->arg->defaultValue)) {
         $so->outputBlankLine();
         $so->output(null, 'The default value for ');
         $so->output($context->argStyle, $switch->arg->name);
         $so->output(null, ' is: ');
         $so->outputLine($context->exampleStyle, $switch->arg->defaultValue);
     }
     $so->addIndent(-4);
     $so->outputBlankLine();
 }