From 2905adb88894cb1b0091836351796822db978e15 Mon Sep 17 00:00:00 2001 From: GautierMichelin Date: Sun, 29 Mar 2015 13:01:50 +0200 Subject: [PATCH] #1 : option to check if Slack.app is running --- src/Sqwack/Command/CronCommand.php | 5 +++++ src/Sqwack/Command/SnapCommand.php | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Sqwack/Command/CronCommand.php b/src/Sqwack/Command/CronCommand.php index 7fa2edf..a6b7581 100644 --- a/src/Sqwack/Command/CronCommand.php +++ b/src/Sqwack/Command/CronCommand.php @@ -20,6 +20,7 @@ protected function configure() $this->addOption('device', 'd', InputOption::VALUE_REQUIRED, 'The name of camera to use. Use `imagesnap -l` to find a list of available devices.'); $this->addOption('team', 't', InputOption::VALUE_REQUIRED, 'The team domain, e.g. "test" if you access Slack on https://test.slack.com.'); $this->addOption('sleep', 's', InputOption::VALUE_REQUIRED, 'The number of minutes to wait before taking the next photo. Defaults to 3.'); + $this->addOption('slack-app-open', 'a', InputOption::VALUE_OPTIONAL, "Don't snap if Slack.app is not running. Default to 0."); } protected function execute(InputInterface $input, OutputInterface $output) @@ -42,6 +43,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $snapOptions['--team'] = $input->getOption('team'); } + if ($input->getOption('slack-app-open')) { + $snapOptions['--slack-app-open'] = $input->getOption('slack-app-open'); + } + $snapInput = new ArrayInput($snapOptions); while (true) { diff --git a/src/Sqwack/Command/SnapCommand.php b/src/Sqwack/Command/SnapCommand.php index 6c9c627..4961f21 100644 --- a/src/Sqwack/Command/SnapCommand.php +++ b/src/Sqwack/Command/SnapCommand.php @@ -23,6 +23,7 @@ protected function configure() $this->addOption('device', 'd', InputOption::VALUE_REQUIRED, 'The name of camera to use. Use `imagesnap -l` to find a list of available devices.'); $this->addOption('team', 't', InputOption::VALUE_REQUIRED, 'The team domain, e.g. "test" if you access Slack on https://test.slack.com.'); + $this->addOption('slack-app-open', 'a', InputOption::VALUE_OPTIONAL, "Don't snap if Slack.app is not running. Default to 0."); } protected function execute(InputInterface $input, OutputInterface $output) @@ -38,6 +39,17 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \InvalidArgumentException('The team domain option --team must be provided'); } + if ($input->getOption('slack-app-open')) { + $exec_result=null; + // Next command tries to see if Slack.app is running, if so, we get back a 1 with some spaces as a result + // if not we get back a 0 with some spaces before + exec('ps aux | grep "[S]lack.app" | wc -l',$exec_result); + $slackapp_is_running = $exec_result[0]*1; + if(!$slackapp_is_running) { + $output->writeln('slack-app-open option is set but Slack.app is not running'); + } + } + $client = new Client([ 'base_url' => sprintf('https://%s.slack.com', $team), 'defaults' => [