setDescription('watch command'); $this->addOption('config', 'C', InputOption::VALUE_OPTIONAL, '', '.watcher.php'); $this->addOption('file', 'F', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, '', []); $this->addOption('dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, '', []); $this->addOption('no-restart', 'N', InputOption::VALUE_NONE, 'Whether no need to restart server'); } public function handle() { $options = (array) include dirname(__DIR__, 2) . '/publish/watcher.php'; if (file_exists($configFile = $this->input->getOption('config'))) { $options = array_replace($options, (array) include $configFile); } elseif (file_exists($configFile = BASE_PATH . '/config/autoload/watcher.php')) { // Compatible with old version, will be removed in the v3.1. $options = array_replace($options, (array) include $configFile); } $option = make(Option::class, [ 'options' => $options, 'dir' => $this->input->getOption('dir'), 'file' => $this->input->getOption('file'), 'restart' => ! $this->input->getOption('no-restart'), ]); $watcher = make(Watcher::class, [ 'option' => $option, 'output' => $this->output, ]); $watcher->run(); } }