/** * Processes a list of input arguments * * @param \r8\CLI\Input $input * @return \r8\CLI\Result */ public function process(\r8\CLI\Input $input) { $result = new \r8\CLI\Result(); // Loop over all the flags and process each in turn while ($input->hasNextOption()) { $flag = $input->popOption(); $option = $this->findByFlag($flag); if ($option === NULL) { throw new \r8\Exception\Data($flag, "Flag", "Unrecognized flag"); } if (!$option->allowMany() && $result->flagExists($flag)) { throw new \r8\Exception\Data($option, "Flag", "Flag can not appear multiple times"); } $result->addOption($option, $option->consume($input)); } // Now collect any command level arguments foreach ($this->args as $arg) { $result->addArgs($arg->consume($input)); } // If there are any arguments left over, let someone know if ($input->hasNextArg()) { throw new \r8\Exception\Data("Flag", $input->popArgument(), "Unrecognized flag"); } return $result; }