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\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
class SelfUpdate extends Command |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $version; |
23
|
|
|
/** |
24
|
|
|
* @var Updater |
25
|
|
|
*/ |
26
|
|
|
protected $updater; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
protected function configure() |
32
|
|
|
{ |
33
|
|
|
$this |
34
|
|
|
->setName('self-update') |
35
|
|
|
->setDescription('Update Cecil to the latest version') |
36
|
|
|
->setDefinition( |
37
|
|
|
new InputDefinition([ |
38
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'If specified, use the given path as working directory'), |
39
|
|
|
]) |
40
|
|
|
) |
41
|
|
|
->setHelp('The self-update command checks for a newer version, and, if found, downloads and installs the latest.'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$this->version = $this->getApplication()->getVersion(); |
50
|
|
|
|
51
|
|
|
$this->updater = new Updater(null, false, Updater::STRATEGY_GITHUB); |
52
|
|
|
/* @var $strategy \Humbug\SelfUpdate\Strategy\GithubStrategy */ |
53
|
|
|
$strategy = $this->updater->getStrategy(); |
54
|
|
|
$strategy->setPackageName('cecil/cecil'); |
55
|
|
|
$strategy->setPharName('cecil.phar'); |
56
|
|
|
$strategy->setCurrentLocalVersion($this->version); |
57
|
|
|
$strategy->setStability('any'); |
58
|
|
|
|
59
|
|
|
try { |
60
|
|
|
$output->writeln('Checks for updates...'); |
61
|
|
|
$result = $this->updater->update(); |
62
|
|
|
if ($result) { |
63
|
|
|
$new = $this->updater->getNewVersion(); |
64
|
|
|
$old = $this->updater->getOldVersion(); |
65
|
|
|
$output->writeln(sprintf('Updated from %s to %s.', $old, $new)); |
66
|
|
|
|
67
|
|
|
return 0; |
68
|
|
|
} |
69
|
|
|
$output->writeln(sprintf('You are already using last version (%s).', $this->version)); |
70
|
|
|
|
71
|
|
|
return 0; |
72
|
|
|
} catch (\Exception $e) { |
73
|
|
|
echo $e->getMessage(); |
74
|
|
|
|
75
|
|
|
return 1; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return 0; |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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
@return
annotation as described here.