Example #1
0
 /**
  * @covers Yeriomin\Getopt\OptionDefinition::setRequired
  */
 public function testSetRequired()
 {
     $this->assertEquals(false, $this->object->getRequired(), '$isRequired is expected to be false by default');
     $this->object->setRequired();
     $this->assertEquals(true, $this->object->getRequired());
     $this->object->setRequired(false);
     $this->assertEquals(false, $this->object->getRequired());
     $this->object->setRequired(true);
     $this->assertEquals(true, $this->object->getRequired());
     $this->object->setRequired(false);
     $this->assertEquals(false, $this->object->getRequired());
     $this->object->setRequired('asd');
     $this->assertEquals(true, $this->object->getRequired());
 }
Example #2
0
 /**
  * Get option value based on its definition
  *
  * @param \Yeriomin\Getopt\OptionDefinition $definition
  * @return mixed
  * @throws GetoptException
  */
 private function getOptionValue(OptionDefinition $definition)
 {
     $nameShort = $definition->getShort();
     $nameLong = $definition->getLong();
     $valueShort = $this->parser->getOptionShort($nameShort);
     $valueLong = $this->parser->getOptionLong($nameLong);
     if ($nameShort !== null && $nameLong !== null && $valueShort !== null && $valueLong !== null && $valueShort !== $valueLong) {
         throw new GetoptException('Both -' . $nameShort . ' and --' . $nameLong . ' given, with non-matching values. Make up your mind.');
     }
     return $valueShort !== null ? $valueShort : $valueLong;
 }
Example #3
0
 /**
  * Get a human-readable string definition of an option
  *
  * @param \Yeriomin\Getopt\OptionDefinition $option
  * @return string
  */
 private function getOptionString(OptionDefinition $option)
 {
     $short = $option->getShort();
     $long = $option->getLong();
     $result = ' ';
     if ($short !== null && $long !== null) {
         $result .= '-' . $short . ', --' . $long;
     } else {
         $result .= $short !== null ? '-' . $short : '--' . $long;
     }
     return $result;
 }