Needs behaves a bit strangely and should interact with "requires" but doesn't. It's actually acting as a defacto "requires". Even if a "needed" command isn't "required" Commando will still throw an exception if it is specified as needed by an unused argument.
In the last one the "needs" clause says that "b needs c" even though c isn't a required argument and b wasn't even specified.
The fix in my local branch is to replace the current "needs" block in Command.php with the following:
// See if our options have what they require
foreach ($keyvals as $key => $value) {
$option = $this->getOption($key);
if(!is_null($option->getValue()) || $option->isRequired()){
$needs = $option->hasNeeds($this->options);
if ($needs !== true) {
throw new \InvalidArgumentException(
'Option "'.$option->getName().'" does not have required option(s): '.implode(', ', $needs)
);
}
}
}
But I'd like to know if the current behaviour of "needs" also acting as a defacto "requires" is actually the desired behaviour before I upload it and submit a pull request.
Needs behaves a bit strangely and should interact with "requires" but doesn't. It's actually acting as a defacto "requires". Even if a "needed" command isn't "required" Commando will still throw an exception if it is specified as needed by an unused argument.
E.g
The following command should run:
Only this should fail
But this also (incorrectly) fails:
In the last one the "needs" clause says that "b needs c" even though c isn't a required argument and b wasn't even specified.
The fix in my local branch is to replace the current "needs" block in Command.php with the following:
But I'd like to know if the current behaviour of "needs" also acting as a defacto "requires" is actually the desired behaviour before I upload it and submit a pull request.