Skip to content

Commit

Permalink
fixing the bug with the missing last param
Browse files Browse the repository at this point in the history
  • Loading branch information
stdakov committed Dec 21, 2019
1 parent 09fd905 commit 9bda08f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 6 additions & 1 deletion example/script.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

//php script.php command subCommand -a value1 -bc 'value2' --param1 value3 --param2 --pa "value4" --vk value5
//php script.php command subCommand -a value1 -bc 'value2' --param1 value3 --param2 --pa "value4" --vk value5 -d

chdir(dirname(dirname(__FILE__)));

Expand Down Expand Up @@ -51,4 +51,9 @@ function dd($a)
throw new Exception("Missing or wrong paramerter");
}

if ($terminal->getParameter("d") !== true) {
throw new Exception("Missing or wrong paramerter");
}


dd($terminal->getParams());
11 changes: 4 additions & 7 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public function setParameter($name, $value)
throw new \InvalidArgumentException("Wrong parameter name '" . $name . "'");
}

if (array_key_exists($name, $this->params)) {
throw new \InvalidArgumentException("Parameter name '" . $name . "' has already been set");
}
// if (array_key_exists($name, $this->params)) {
// throw new \InvalidArgumentException("Parameter name '" . $name . "' has already been set");
// }

$this->params[$name] = $value;

Expand Down Expand Up @@ -168,12 +168,9 @@ protected function parseParams($arguments)
foreach ($arguments as $argument) {

if (strpos($argument, "-") === 0) {
if ($currentParamName != null) {
$this->setParameter($currentParamName, true);
}

$currentParamName = ltrim(trim($argument), '-');

$this->setParameter($currentParamName, true);

if (strpos($argument, "--") === 0) {
if (strlen($currentParamName) < 2) {
Expand Down

0 comments on commit 9bda08f

Please sign in to comment.