protected function getArgcArgv() { if (empty($this->commands)) { return parent::getArgcArgv(); } list($argc, $argv) = parent::getArgcArgv(); // Obtain the list of options $opts = array(); foreach ($this->options as $opt) { $opts[] = $opt->short_name; $opts[] = $opt->long_name; } // Get commands $commands = array(); foreach ($this->commands as $cmd) { $commands[] = $cmd->name; $commands = array_merge($commands, $cmd->aliases); } // Inject default command if none given $commands = array_keys($this->commands); for ($i = 1; $i < $argc; $i++) { if (!in_array($argv[$i], $opts) && !in_array($argv[$i], $commands)) { array_splice($argv, $i, 0, $commands[0]); $argc++; break; } } return array($argc, $argv); }