/** * Given an input of arguments, pops elements off, filters them, validates * them and returns an array of everything it consumes * * @param \r8\CLI\Input $input The input list to consume * @return Array */ public function consume(\r8\CLI\Input $input) { $result = array(); while ($input->hasNextArg()) { $arg = $this->getFilter()->filter($input->popArgument()); $this->getValidator()->ensure($arg); $result[] = $arg; } return $result; }
/** * Given an input of arguments, pops elements off, filters them, validates * them and returns an array of everything it consumes * * @param \r8\CLI\Input $input The input list to consume * @return Array */ public function consume(\r8\CLI\Input $input) { $arg = $this->getFilter()->filter($input->popArgument()); $this->getValidator()->ensure($arg); return array($arg); }
/** * 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; }