Beispiel #1
0
 /**
  * Compiles options in a command
  *
  * @param ICommand $command The command to compile
  * @param IRequest $request The user request
  */
 protected function compileOptions(ICommand &$command, IRequest $request)
 {
     foreach ($command->getOptions() as $option) {
         $shortNameIsSet = $request->optionIsSet($option->getShortName());
         $longNameIsSet = $request->optionIsSet($option->getName());
         // All options are optional (duh)
         if ($shortNameIsSet || $longNameIsSet) {
             if ($longNameIsSet) {
                 $value = $request->getOptionValue($option->getName());
             } else {
                 $value = $request->getOptionValue($option->getShortName());
             }
             if (!$option->valueIsPermitted() && $value !== null) {
                 throw new RuntimeException("Option \"{$option->getName()}\" does not permit a value");
             }
             if ($option->valueIsRequired() && $value === null) {
                 throw new RuntimeException("Option \"{$option->getName()}\" requires a value");
             }
             if ($option->valueIsOptional() && $value == null) {
                 $value = $option->getDefaultValue();
             }
             $command->setOptionValue($option->getName(), $value);
         }
     }
 }
Beispiel #2
0
 /**
  * Gets whether or not the input is invoking the version command
  *
  * @param IRequest $request The parsed request
  * @return bool True if it is invoking the version command, otherwise false
  */
 private function isInvokingVersionCommand(IRequest $request)
 {
     return $request->optionIsSet("v") || $request->optionIsSet("version");
 }