|
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\GroupsListPayload; |
|
15
|
|
|
use CL\Slack\Payload\GroupsListPayloadResponse; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class GroupsListCommand extends AbstractApiCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::configure(); |
|
29
|
|
|
|
|
30
|
|
|
$this->setName('groups:list'); |
|
31
|
|
|
$this->setDescription('Returns a list of all groups in your Slack team'); |
|
32
|
|
|
$this->addOption('exclude-archived', null, InputOption::VALUE_OPTIONAL, 'Don\'t return archived groups.'); |
|
33
|
|
|
$this->setHelp(<<<EOT |
|
34
|
|
|
This method returns a list of groups in the team that the caller is in and archived groups that the caller was in. |
|
35
|
|
|
The list of (non-deactivated) members in each group is also returned. |
|
36
|
|
|
|
|
37
|
|
|
For more information about the related API method, check out the official documentation: |
|
38
|
|
|
<comment>https://api.slack.com/methods/groups.list</comment> |
|
39
|
|
|
EOT |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return GroupsListPayload |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function createPayload() |
|
47
|
|
|
{ |
|
48
|
|
|
$payload = new GroupsListPayload(); |
|
49
|
|
|
$payload->setExcludeArchived($this->input->getOption('exclude-archived')); |
|
50
|
|
|
|
|
51
|
|
|
return $payload; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
* |
|
57
|
|
|
* @param GroupsListPayloadResponse $payloadResponse |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function handleResponse($payloadResponse) |
|
60
|
|
|
{ |
|
61
|
|
|
if ($payloadResponse->isOk()) { |
|
62
|
|
|
$groups = $payloadResponse->getGroups(); |
|
63
|
|
|
$this->output->writeln(sprintf('Received <comment>%d</comment> groups...', count($groups))); |
|
64
|
|
|
if (!empty($groups)) { |
|
65
|
|
|
$rows = []; |
|
66
|
|
|
foreach ($payloadResponse->getGroups() as $group) { |
|
67
|
|
|
$row = $this->serializeObjectToArray($group); |
|
68
|
|
|
$row['purpose'] = !$group->getPurpose() ?: $group->getPurpose()->getValue(); |
|
69
|
|
|
$row['topic'] = !$group->getTopic() ?: $group->getTopic()->getValue(); |
|
70
|
|
|
|
|
71
|
|
|
$rows[] = $row; |
|
72
|
|
|
} |
|
73
|
|
|
$this->renderTable($rows, null); |
|
74
|
|
|
$this->writeOk('Finished listing groups'); |
|
75
|
|
|
} else { |
|
76
|
|
|
$this->writeComment('No groups to list'); |
|
77
|
|
|
} |
|
78
|
|
|
} else { |
|
79
|
|
|
$this->writeError(sprintf('Failed to list groups. %s', lcfirst($payloadResponse->getErrorExplanation()))); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|