projects
/
pharext
/
pharext
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
more refactoring; now the package hook starts to make sense
[pharext/pharext]
/
src
/
pharext
/
Cli
/
Args.php
diff --git
a/src/pharext/Cli/Args.php
b/src/pharext/Cli/Args.php
index 49d85ab7cb84133b069b1bcdbf665eded066da2b..38cfaca80e862546f06f989e13d7c9844c6f46cb 100644
(file)
--- a/
src/pharext/Cli/Args.php
+++ b/
src/pharext/Cli/Args.php
@@
-67,24
+67,27
@@
class Args implements \ArrayAccess
/**
* Compile the original spec
/**
* Compile the original spec
- * @param array $spec
+ * @param array
|Traversable
$spec
*/
*/
- public function __construct(array $spec = null) {
- $this->compile($spec);
+ public function __construct($spec = null) {
+ if (is_array($spec) || $spec instanceof Traversable) {
+ $this->compile($spec);
+ }
+
}
/**
* Compile the original spec
}
/**
* Compile the original spec
- * @param array $spec
+ * @param array
|Traversable
$spec
* @return pharext\CliArgs self
*/
* @return pharext\CliArgs self
*/
- public function compile(array $spec = null) {
- $this->orig = array_merge($this->orig, (array) $spec);
- foreach ((array) $spec as $arg) {
+ public function compile($spec) {
+ foreach ($spec as $arg) {
if (isset($arg[0])) {
$this->spec["-".$arg[0]] = $arg;
}
$this->spec["--".$arg[1]] = $arg;
if (isset($arg[0])) {
$this->spec["-".$arg[0]] = $arg;
}
$this->spec["--".$arg[1]] = $arg;
+ $this->orig[] = $arg;
}
return $this;
}
}
return $this;
}
@@
-167,7
+170,7
@@
class Args implements \ArrayAccess
return $spec[3] & self::REQUIRED;
});
foreach ($required as $req) {
return $spec[3] & self::REQUIRED;
});
foreach ($required as $req) {
- if (!
isset
($this[$req[0]])) {
+ if (!
strlen
($this[$req[0]])) {
yield sprintf("Option --%s is required", $req[1]);
}
}
yield sprintf("Option --%s is required", $req[1]);
}
}