public function run($command = null)
{
$message = 'Lithium console started in the ' . Environment::get() . ' environment.';
$message .= ' Use the --env=environment key to alter this.';
$this->out($message);
if (!$command) {
$this->_renderCommands();
return true;
}
if (!preg_match('/\\\\/', $command)) {
$command = Inflector::camelize($command);
}
if (!($class = Libraries::locate('command', $command))) {
$this->error("Command `{$command}` not found");
return false;
}
if (strpos($command, '\\') !== false) {
$command = join('', array_slice(explode("\\", $command), -1));
}
$command = strtolower(Inflector::slug($command));
$run = null;
$methods = $this->_methods($class);
$properties = $this->_properties($class);
$info = Inspector::info($class);
$this->out('USAGE', 'heading');
if (isset($methods['run'])) {
$run = $methods['run'];
unset($methods['run']);
$this->_renderUsage($command, $run, $properties);
}
foreach ($methods as $method) {
$this->_renderUsage($command, $method);
}
if (!empty($info['description'])) {
$this->nl();
$this->_renderDescription($info);
$this->nl();
}
if ($properties || $methods) {
$this->out('OPTIONS', 'heading');
}
if ($run) {
$this->_render($run['args']);
}
if ($methods) {
$this->_render($methods);
}
if ($properties) {
$this->_render($properties);
}
return true;
}