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\UsersListPayload; |
15
|
|
|
use CL\Slack\Payload\UsersListPayloadResponse; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Cas Leentfaar <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class UsersListCommand extends AbstractApiCommand |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritDoc} |
24
|
|
|
*/ |
25
|
|
|
protected function configure() |
26
|
|
|
{ |
27
|
|
|
parent::configure(); |
28
|
|
|
|
29
|
|
|
$this->setName('users:list'); |
30
|
|
|
$this->setDescription('Returns a list of all users in the team (including deleted/deactivated users)'); |
31
|
|
|
$this->setHelp(<<<EOT |
32
|
|
|
The <info>users:list</info> command returns a list of all users in the team. This includes deleted/deactivated users. |
33
|
|
|
|
34
|
|
|
For more information about the related API method, check out the official documentation: |
35
|
|
|
<comment>https://api.slack.com/methods/users.list</comment> |
36
|
|
|
EOT |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return UsersListPayload |
42
|
|
|
*/ |
43
|
|
|
protected function createPayload() |
44
|
|
|
{ |
45
|
|
|
$payload = new UsersListPayload(); |
46
|
|
|
|
47
|
|
|
return $payload; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
* |
53
|
|
|
* @param UsersListPayloadResponse $payloadResponse |
54
|
|
|
*/ |
55
|
|
|
protected function handleResponse($payloadResponse) |
56
|
|
|
{ |
57
|
|
|
if ($payloadResponse->isOk()) { |
58
|
|
|
$users = $payloadResponse->getUsers(); |
59
|
|
|
$this->output->writeln(sprintf('Received <comment>%d</comment> users...', count($users))); |
60
|
|
|
if (!empty($users)) { |
61
|
|
|
$this->renderTable($users, null); |
62
|
|
|
$this->writeOk('Successfully listed users'); |
63
|
|
|
} else { |
64
|
|
|
$this->writeError('No users seem to be assigned to your team... this is strange...'); |
65
|
|
|
} |
66
|
|
|
} else { |
67
|
|
|
$this->writeError(sprintf('Failed to list users: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|