setName("watch") ->setDescription("Watch files and take action when they are modified") ->addOption("interval", "N", InputOption::VALUE_REQUIRED, "Interval between polls", 5) ; } protected function execute(InputInterface $input, OutputInterface $output) { /** @var WatcherPlug $plugin */ $plugin = get_plugin('com.noccy.watcher'); $config = read_config('watchers.json'); $iv = max(1, (int)$input->getOption('interval')); if (!($plugin && $config)) { $output->writeln("Missing or bad config file watchers.json?"); return Command::FAILURE; } $watcher = $plugin->getFileWatcher(); foreach ($config['watchers'] as $ruleconf) { $rule = Rule::createFromConfig($ruleconf); $watcher->addRule($rule); } while (true) { $watcher->loop(); sleep($iv); } return Command::SUCCESS; } }