/**
* Creates an Help object from a class subclassing Command
*
* @param string $name
* @param string $subCommand
* @return Help
*/
public static function fromCommandClass($name, $subCommand = null)
{
$prefix = 'execute';
$class = new ReflectionClass($name);
if ($subCommand) {
$method = $prefix . ucfirst(Utils::camelize($subCommand));
if (!$class->hasMethod($method)) {
throw new ConsoleException("Sub command '{$subCommand}' of '{$name}' does not exist");
}
return new Help($class->getMethod($method)->getDocComment());
}
$help = new Help($class->getDocComment());
foreach ($class->getMethods() as $method) {
if (strlen($method->getName()) > strlen($prefix) && substr($method->getName(), 0, strlen($prefix)) === $prefix) {
$help->subCommands[] = Utils::dashized(substr($method->getName(), strlen($prefix)));
}
}
return $help;
}