forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdit.php
More file actions
71 lines (61 loc) · 1.62 KB
/
Edit.php
File metadata and controls
71 lines (61 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace kriskbx\gtt\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
class Edit extends Command
{
/**
* @var string
*/
protected $configFile;
/**
* Edit constructor.
*
* @param string $configFile
*/
public function __construct($configFile)
{
$this->configFile = $configFile;
parent::__construct(null);
}
/**
* Configure Command.
*/
public function configure()
{
$this->setName('edit')
->setDescription('Open the global configuration file in your default editor');
}
/**
* Execute Command.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$command = $this->executable() . ' ' . $this->configFile;
$process = new Process($command, realpath(__DIR__ . '/../'), array_merge($_SERVER, $_ENV), null, null);
$process->run(function ($type, $line) use ($output) {
$output->write($line);
});
}
/**
* Find the correct executable to run depending on the OS.
*
* @return string
*/
protected function executable()
{
if (strpos(strtoupper(PHP_OS), 'WIN') === 0) {
return 'start';
} elseif (strpos(strtoupper(PHP_OS), 'DARWIN') === 0) {
return 'open';
}
return 'xdg-open';
}
}