/**
* 运行命令
*
* @param array|null $argv
*
* @return mixed
*/
public function run(array $argv = null)
{
try {
if ($argv === null) {
$argv = isset($_SERVER['argv']) ? array_slice($_SERVER['argv'], 1) : [];
}
list($args, $options) = Input::parse($argv);
$command = count($args) ? array_shift($args) : 'help';
if (!isset($this->commands[$command])) {
throw new \InvalidArgumentException("Command '{$command}' does not exist");
}
isset($options['no-ansi']) && Colour::setNoAnsi();
if (isset($options['h']) || isset($options['help'])) {
$help = new Help($this);
$help->execute([$command]);
exit(0);
}
$command = explode('::', $this->commands[$command]);
return call_user_func_array([new $command[0]($this), isset($command[1]) ? $command[1] : 'execute'], [$args, $options]);
} catch (\Exception $e) {
Output::writeException($e);
exit(1);
}
}