+ protected function doRunCommand(Command $command, Input $input, Output $output)
+ {
+ return $command->run($input, $output);
+ }
+
+ /**
+ * 获取指令的名称
+ * @access protected
+ * @param Input $input 输入实例
+ * @return string
+ */
+ protected function getCommandName(Input $input)
+ {
+ return $input->getFirstArgument();
+ }
+
+ /**
+ * 获取默认输入定义
+ * @access protected
+ * @return InputDefinition
+ */
+ protected function getDefaultInputDefinition()
+ {
+ return new InputDefinition([
+ new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
+ new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'),
+ new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this console version'),
+ new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
+ new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
+ new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'),
+ new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'),
+ new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
+ ]);
+ }
+
+ /**
+ * 获取默认命令
+ * @access protected
+ * @return Command[]
+ */
+ protected function getDefaultCommands()
+ {
+ $defaultCommands = [];
+
+ foreach (self::$defaultCommands as $class) {
+ if (class_exists($class) && is_subclass_of($class, "think\\console\\Command")) {
+ $defaultCommands[] = new $class();
+ }
+ }
+
+ return $defaultCommands;
+ }
+
+ /**
+ * 添加默认指令
+ * @access public
+ * @param array $classes 指令
+ * @return void
+ */
+ public static function addDefaultCommands(array $classes)
+ if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
+ throw new \RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
+ }
+
+ if (0 !== $this->run($callback)) {
+ throw new ProcessFailedException($this);
+ }
+
+ return $this;
+ }
+
+ /**
+ * 启动进程并写到 STDIN 输入后返回。
+ * @param callable|null $callback
+ * @throws \RuntimeException
+ * @throws \RuntimeException
+ * @throws \LogicException
+ */
+ public function start($callback = null)
+ {
+ if ($this->isRunning()) {
+ throw new \RuntimeException('Process is already running');
+ }
+ if ($this->outputDisabled && null !== $callback) {
+ throw new \LogicException('Output has been disabled, enable it to allow the use of a callback.');
+ if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
+ throw new \RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
+ }
+
+ $this->updateStatus(false);
+
+ return $this->exitcode;
+ }
+
+ /**
+ * 获取退出文本
+ * @return null|string
+ */
+ public function getExitCodeText()
+ {
+ if (null === $exitcode = $this->getExitCode()) {