|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the slack-cli package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Cas Leentfaar <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CL\SlackCli\Command; |
|
13
|
|
|
|
|
14
|
|
|
use CL\Slack\Payload\ImListPayload; |
|
15
|
|
|
use CL\Slack\Payload\ImListPayloadResponse; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class ImListCommand extends AbstractApiCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::configure(); |
|
29
|
|
|
|
|
30
|
|
|
$this->setName('im:list'); |
|
31
|
|
|
$this->setDescription('Returns a list of all IM channels in your Slack team'); |
|
32
|
|
|
$this->addOption('exclude-archived', null, InputOption::VALUE_OPTIONAL, 'Don\'t return archived IM channels.'); |
|
33
|
|
|
$this->setHelp(<<<EOT |
|
34
|
|
|
The <info>im:list</info> command returns a list of all IM channels in your Slack team. |
|
35
|
|
|
This includes channels the caller is in, channels they are not currently in, and archived channels. |
|
36
|
|
|
The number of (non-deactivated) members in each channel is also returned. |
|
37
|
|
|
EOT |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return ImListPayload |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function createPayload() |
|
45
|
|
|
{ |
|
46
|
|
|
$payload = new ImListPayload(); |
|
47
|
|
|
$payload->setExcludeArchived($this->input->getOption('exclude-archived')); |
|
48
|
|
|
|
|
49
|
|
|
return $payload; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
* |
|
55
|
|
|
* @param ImListPayloadResponse $payloadResponse |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function handleResponse($payloadResponse) |
|
58
|
|
|
{ |
|
59
|
|
|
if ($payloadResponse->isOk()) { |
|
60
|
|
|
$channels = $payloadResponse->getImChannels(); |
|
61
|
|
|
if (!empty($channels)) { |
|
62
|
|
|
$this->renderTable($channels, null); |
|
63
|
|
|
$this->writeOk('Finished listing channels'); |
|
64
|
|
|
} else { |
|
65
|
|
|
$this->writeComment('No IM channels to list'); |
|
66
|
|
|
} |
|
67
|
|
|
} else { |
|
68
|
|
|
$this->writeError(sprintf('Failed to list channels. %s', lcfirst($payloadResponse->getErrorExplanation()))); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|