|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kasifi\Gitaski\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Humbug\SelfUpdate\Strategy\ShaStrategy; |
|
7
|
|
|
use Humbug\SelfUpdate\Updater; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
12
|
|
|
|
|
13
|
|
|
class SelfUpdateCommand extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* return void |
|
17
|
|
|
*/ |
|
18
|
|
|
protected function configure() |
|
19
|
|
|
{ |
|
20
|
|
|
$this |
|
21
|
|
|
->setName('self-update') |
|
22
|
|
|
->setDescription('Self update of Gitaski binary.'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param InputInterface $input |
|
27
|
|
|
* @param OutputInterface $output |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
* @throws Exception |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
33
|
|
|
{ |
|
34
|
|
|
$io = new SymfonyStyle($input, $output); |
|
35
|
|
|
|
|
36
|
|
|
$updater = new Updater(); |
|
37
|
|
|
$strategy = $updater->getStrategy(); |
|
38
|
|
|
|
|
39
|
|
|
if ($strategy instanceof ShaStrategy) { |
|
40
|
|
|
$strategy->setPharUrl('http://lucascherifi.github.io/gitaski/gitaski.phar'); |
|
41
|
|
|
$strategy->setVersionUrl('http://lucascherifi.github.io/gitaski/gitaski.phar.version'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$result = $updater->update(); |
|
45
|
|
|
if (!$result) { |
|
46
|
|
|
$io = new SymfonyStyle($input, $output); |
|
47
|
|
|
$io->success('No update needed.'); |
|
48
|
|
|
|
|
49
|
|
|
return; |
|
50
|
|
|
} |
|
51
|
|
|
$new = $updater->getNewVersion(); |
|
52
|
|
|
$old = $updater->getOldVersion(); |
|
53
|
|
|
$io->success(sprintf('Updated from %s to %s', $old, $new)); |
|
54
|
|
|
|
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
} |