1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CL\SlackCli\Command; |
4
|
|
|
|
5
|
|
|
use CL\SlackCli\Config\Config; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Cas Leentfaar <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class ConfigEditCommand extends AbstractCommand |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritDoc} |
16
|
|
|
*/ |
17
|
1 |
|
protected function configure() |
18
|
|
|
{ |
19
|
1 |
|
parent::configure(); |
20
|
|
|
|
21
|
1 |
|
$this->setName('config:edit'); |
22
|
1 |
|
$this->setDescription('Edit config options'); |
23
|
|
|
|
24
|
1 |
|
$this->setHelp(<<<EOT |
25
|
|
|
The <info>config:edit</info> command allows you to edit the Slack CLI settings using a pre-configured editor. |
26
|
|
|
|
27
|
|
|
To choose your editor you can set the "SLACK_CONFIG_EDITOR" environment variable. |
28
|
|
|
|
29
|
|
|
To get a list of configuration values in the file, use the `config:list` command: |
30
|
|
|
|
31
|
|
|
<comment>slack.phar config:list</comment> |
32
|
|
|
EOT |
33
|
1 |
|
); |
34
|
1 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
*/ |
39
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
1 |
|
$editor = escapeshellcmd(getenv('SLACK_CONFIG_EDITOR')); |
42
|
1 |
|
if (!$editor) { |
43
|
|
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) { |
44
|
|
|
$editor = 'notepad'; |
45
|
|
|
} else { |
46
|
|
|
foreach (['vim', 'vi', 'nano', 'pico', 'ed'] as $candidate) { |
47
|
|
|
if (exec('which ' . $candidate)) { |
48
|
|
|
$editor = $candidate; |
49
|
|
|
break; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
$file = $this->getConfigPath(); |
56
|
1 |
|
$to = defined('PHP_WINDOWS_VERSION_BUILD') ? '' : ' > `tty`'; |
57
|
1 |
|
$command = sprintf('%s %s%s', $editor, $file, $to); |
58
|
|
|
|
59
|
1 |
|
$this->output->writeln(sprintf('Editing `%s` using `%s`...', $file, $editor)); |
60
|
|
|
|
61
|
1 |
|
if (!$this->isTest()) { |
62
|
|
|
system($command); |
63
|
|
|
} |
64
|
1 |
|
} |
65
|
|
|
} |
66
|
|
|
|