diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/php/argvParser.php b/php/argvParser.php index 05719ac..dcb3f4d 100644 --- a/php/argvParser.php +++ b/php/argvParser.php @@ -25,6 +25,11 @@ class argParsed $this->parsed[$key] = $value; return $this; } + + public function getRest(): string + { + return $this->get('rest', ''); + } } readonly class argvParser @@ -56,18 +61,24 @@ readonly class argvParser $parsed = (new argParsed())->initOptions($this->options); while (str_starts_with($argv[0] ?? '', '-')) { - $option = substr($argv[0], 1); + $option = substr($argv[0], 1, 1); + if (substr($argv[0], 2, 1) === ':') { + $data = substr($argv[0], 3); + } else { + $data = true; + } if ($this->options[$option]) { - $parsed->set($option, true); + $parsed->set($option, $data); } array_shift($argv); } - if (count($argv) !== count($this->arguments)) { + if (count($argv) < count($this->arguments)) { return false; } foreach ($this->arguments as $arg => $description) { $parsed->set($arg, array_shift($argv)); } + $parsed->set('rest', implode(' ', $argv)); return $parsed; }