|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Cecil\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Humbug\SelfUpdate\Updater; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
|
|
18
|
|
|
class CommandSelfUpdate extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $version; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var Updater |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $updater; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function configure() |
|
33
|
|
|
{ |
|
34
|
|
|
$this |
|
35
|
|
|
->setName('self-update') |
|
36
|
|
|
->setAliases(['selfupdate']) |
|
37
|
|
|
->setDescription('Update Cecil to the latest version') |
|
38
|
|
|
->setDefinition( |
|
39
|
|
|
new InputDefinition([ |
|
40
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'If specified, use the given path as working directory'), |
|
41
|
|
|
]) |
|
42
|
|
|
) |
|
43
|
|
|
->setHelp('The self-update command checks for a newer version, and, if found, downloads and installs the latest.'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$this->version = $this->getApplication()->getVersion(); |
|
52
|
|
|
|
|
53
|
|
|
$this->updater = new Updater(null, false, Updater::STRATEGY_GITHUB); |
|
54
|
|
|
/* @var $strategy \Humbug\SelfUpdate\Strategy\GithubStrategy */ |
|
55
|
|
|
$strategy = $this->updater->getStrategy(); |
|
56
|
|
|
$strategy->setPackageName('cecil/cecil'); |
|
57
|
|
|
$strategy->setPharName('cecil.phar'); |
|
58
|
|
|
$strategy->setCurrentLocalVersion($this->version); |
|
59
|
|
|
$strategy->setStability('any'); |
|
60
|
|
|
|
|
61
|
|
|
try { |
|
62
|
|
|
$output->writeln('Checks for updates...'); |
|
63
|
|
|
$result = $this->updater->update(); |
|
64
|
|
View Code Duplication |
if ($result) { |
|
|
|
|
|
|
65
|
|
|
$new = $this->updater->getNewVersion(); |
|
66
|
|
|
$old = $this->updater->getOldVersion(); |
|
67
|
|
|
$output->writeln(sprintf('Updated from %s to %s.', $old, $new)); |
|
68
|
|
|
|
|
69
|
|
|
return 0; |
|
70
|
|
|
} |
|
71
|
|
|
$output->writeln(sprintf('You are already using last version (%s).', $this->version)); |
|
72
|
|
|
|
|
73
|
|
|
return 0; |
|
74
|
|
|
} catch (\Exception $e) { |
|
75
|
|
|
echo $e->getMessage(); |
|
76
|
|
|
|
|
77
|
|
|
return 1; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return 0; |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.