X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fpharext%2FCli%2FArgs.php;h=ef46e88a4cb286794da15f70a2069ae2d9768300;hb=d86a65973ac3cd8647354274ab9af6ce8c8257fc;hp=c248a74dcc964c81c089d1b2204a8cacfe3dcfb0;hpb=ef9078606945dbc55d85a50614bbc25734aa378a;p=pharext%2Fpharext diff --git a/src/pharext/Cli/Args.php b/src/pharext/Cli/Args.php index c248a74..ef46e88 100644 --- a/src/pharext/Cli/Args.php +++ b/src/pharext/Cli/Args.php @@ -128,14 +128,14 @@ class Args implements \ArrayAccess for ($f = false, $p = 0, $i = 0; $i < $argc; ++$i) { $o = $argv[$i]; - if ($o{0} === "-" && strlen($o) > 2 && $o{1} !== "-") { + if ($o[0] === "-" && strlen($o) > 2 && $o[1] !== "-") { // multiple short opts, e.g. -vps $argc += strlen($o) - 2; array_splice($argv, $i, 1, array_map(function($s) { return "-$s"; }, str_split(substr($o, 1)))); $o = $argv[$i]; - } elseif ($o{0} === "-" && strlen($o) > 2 && $o{1} === "-" && 0 < ($eq = strpos($o, "="))) { + } elseif ($o[0] === "-" && strlen($o) > 2 && $o[1] === "-" && 0 < ($eq = strpos($o, "="))) { // long opt with argument, e.g. --foo=bar $argc++; array_splice($argv, $i, 1, [ @@ -150,7 +150,7 @@ class Args implements \ArrayAccess } if ($f || !isset($this->spec[$o])) { - if ($o{0} !== "-" && isset($this->spec["--$p"])) { + if ($o[0] !== "-" && isset($this->spec["--$p"])) { $this[$p] = $o; if (!$this->optIsMulti($p)) { ++$p; @@ -207,7 +207,7 @@ class Args implements \ArrayAccess $args = []; foreach ($this->spec as $spec) { $opt = $this->opt($spec[1]); - $args[$opt] = $this[$opt]; + $args[$opt] = is_numeric($spec[0]) ? $this[$spec[0]] : $this[$opt]; } return $args; } @@ -316,7 +316,7 @@ class Args implements \ArrayAccess if (is_numeric($o)) { return "--$o"; } - if ($o{0} !== '-') { + if ($o[0] !== '-') { if (strlen($o) > 1) { $o = "-$o"; }