1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Storeman\Cli\Command; |
4
|
|
|
|
5
|
|
|
use Storeman\Cli\Helper\DisplayIndexHelper; |
6
|
|
|
use Storeman\Storeman; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class ShowIndexCommand extends AbstractCommand |
12
|
|
|
{ |
13
|
|
|
protected function configure() |
14
|
|
|
{ |
15
|
|
|
parent::configure(); |
16
|
|
|
|
17
|
|
|
$this->setName('show-index'); |
18
|
|
|
$this->setDescription('Displays an index'); |
19
|
|
|
$this->addArgument('revision', InputArgument::OPTIONAL, 'Revision number, \'latest\' or \'local\'. Defaults to \'latest\'.', 'latest'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function executeConfigured(InputInterface $input, OutputInterface $output, Storeman $storeman): int |
23
|
|
|
{ |
24
|
|
|
$revision = $input->getArgument('revision'); |
25
|
|
|
$index = null; |
26
|
|
|
|
27
|
|
|
if ($revision === 'latest') |
28
|
|
|
{ |
29
|
|
|
$revision = $storeman->getLastRevision(); |
30
|
|
|
|
31
|
|
|
if ($revision === null) |
32
|
|
|
{ |
33
|
|
|
$this->consoleStyle->writeln("Could not find any past synchronizations to show."); |
34
|
|
|
|
35
|
|
|
return 0; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
elseif ($revision === 'local') |
39
|
|
|
{ |
40
|
|
|
$index = $storeman->getLocalIndex(); |
41
|
|
|
} |
42
|
|
|
elseif (ctype_digit($revision)) |
43
|
|
|
{ |
44
|
|
|
$revision = intval($revision); |
45
|
|
|
} |
46
|
|
|
else |
47
|
|
|
{ |
48
|
|
|
$this->consoleStyle->error("Argument 'revision' invalid."); |
49
|
|
|
|
50
|
|
|
return 1; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($index === null) |
54
|
|
|
{ |
55
|
|
|
assert(is_int($revision)); |
56
|
|
|
|
57
|
|
|
$vaults = $storeman->getVaultContainer(); |
58
|
|
|
$vault = $vaults->getPrioritizedVault($vaults->getVaultsHavingRevision($revision)); |
59
|
|
|
|
60
|
|
|
if ($vault === null) |
61
|
|
|
{ |
62
|
|
|
$this->consoleStyle->error("Could not find requested revision {$revision} in any vault."); |
63
|
|
|
|
64
|
|
|
return 1; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$index = $vault->loadRemoteIndex($revision); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** @var DisplayIndexHelper $displayIndexHelper */ |
71
|
|
|
$displayIndexHelper = $this->getHelper('displayIndex'); |
72
|
|
|
$displayIndexHelper->displayIndex($index, $output); |
|
|
|
|
73
|
|
|
|
74
|
|
|
return 0; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: