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\GroupsRenamePayload; |
15
|
|
|
use CL\Slack\Payload\GroupsRenamePayloadResponse; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Cas Leentfaar <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class GroupsRenameCommand extends AbstractApiCommand |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritDoc} |
26
|
|
|
*/ |
27
|
|
|
protected function configure() |
28
|
|
|
{ |
29
|
|
|
parent::configure(); |
30
|
|
|
|
31
|
|
|
$this->setName('groups:rename'); |
32
|
|
|
$this->setDescription('Leave a group (as the user of the token).'); |
33
|
|
|
$this->addArgument('group-id', InputArgument::REQUIRED, 'The ID of the group to rename'); |
34
|
|
|
$this->addArgument('name', InputArgument::REQUIRED, 'The new name for this group'); |
35
|
|
|
$this->setHelp(<<<EOT |
36
|
|
|
The <info>groups:rename</info> command renames a team group. |
37
|
|
|
|
38
|
|
|
The only people who can rename a group are team admins, or the person that originally created the group. |
39
|
|
|
Others will receive a "not_authorized" error. |
40
|
|
|
|
41
|
|
|
For more information about the related API method, check out the official documentation: |
42
|
|
|
<comment>https://api.slack.com/methods/groups.rename</comment> |
43
|
|
|
EOT |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return GroupsRenamePayload |
49
|
|
|
*/ |
50
|
|
|
protected function createPayload() |
51
|
|
|
{ |
52
|
|
|
$payload = new GroupsRenamePayload(); |
53
|
|
|
$payload->setGroupId($this->input->getArgument('group-id')); |
54
|
|
|
$payload->setName($this->input->getArgument('name')); |
55
|
|
|
|
56
|
|
|
return $payload; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
* |
62
|
|
|
* @param GroupsRenamePayloadResponse $payloadResponse |
63
|
|
|
*/ |
64
|
|
|
protected function handleResponse($payloadResponse) |
65
|
|
|
{ |
66
|
|
|
if ($payloadResponse->isOk()) { |
67
|
|
|
$this->writeOk('Successfully renamed group!'); |
68
|
|
|
if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) { |
69
|
|
|
$this->output->writeln('Renamed group:'); |
70
|
|
|
$data = $this->serializeObjectToArray($payloadResponse->getGroup()); |
71
|
|
|
$this->renderKeyValueTable($data); |
72
|
|
|
} |
73
|
|
|
} else { |
74
|
|
|
$this->writeError(sprintf('Failed to leave group: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|