Example #1
0
 /**
  * @covers Yeriomin\Getopt\OptionDefinition::setLong
  */
 public function testSetLong()
 {
     $this->assertEquals(null, $this->object->getLong(), '$long is expected to be null by default');
     $this->object->setLong('abc');
     $this->assertEquals('abc', $this->object->getLong());
 }
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;
 }