setName("info")
->addOption(
'force',
'f',
InputOption::VALUE_NONE,
'Force fetching the new data remotely'
)
->addOption(
'all-yes',
'y',
InputOption::VALUE_NONE,
'Assumes yes (or best approach) instead of prompting'
)
->addArgument(
'package',
InputArgument::REQUIRED,
'The package of which more informations are desired. Use the "index" command for a list of packages'
)
->setDescription("Shows more informations about a package")
->setHelp('The info shows more informations about a package');
}
/**
* @return int|null|void
*/
protected function serve()
{
$this->gpm = new GPM($this->input->getOption('force'));
$this->all_yes = $this->input->getOption('all-yes');
$this->displayGPMRelease();
$foundPackage = $this->gpm->findPackage($this->input->getArgument('package'));
if (!$foundPackage) {
$this->output->writeln("The package '" . $this->input->getArgument('package') . "' was not found in the Grav repository.");
$this->output->writeln('');
$this->output->writeln("You can list all the available packages by typing:");
$this->output->writeln(" " . $this->argv . " index");
$this->output->writeln('');
exit;
}
$this->output->writeln("Found package '" . $this->input->getArgument('package') . "' under the '" . ucfirst($foundPackage->package_type) . "' section");
$this->output->writeln('');
$this->output->writeln("" . $foundPackage->name . " [" . $foundPackage->slug . "]");
$this->output->writeln(str_repeat('-', strlen($foundPackage->name) + strlen($foundPackage->slug) + 3));
$this->output->writeln("" . strip_tags($foundPackage->description_plain) . "");
$this->output->writeln('');
$packageURL = '';
if (isset($foundPackage->author['url'])) {
$packageURL = '<' . $foundPackage->author['url'] . '>';
}
$this->output->writeln("" . str_pad("Author",
12) . ": " . $foundPackage->author['name'] . ' <' . $foundPackage->author['email'] . '> ' . $packageURL);
foreach ([
'version',
'keywords',
'date',
'homepage',
'demo',
'docs',
'guide',
'repository',
'bugs',
'zipball_url',
'license'
] as $info) {
if (isset($foundPackage->$info)) {
$name = ucfirst($info);
$data = $foundPackage->$info;
if ($info == 'zipball_url') {
$name = "Download";
}
if ($info == 'date') {
$name = "Last Update";
$data = date('D, j M Y, H:i:s, P ', strtotime('2014-09-16T00:07:16Z'));
}
$name = str_pad($name, 12);
$this->output->writeln("" . $name . ": " . $data);
}
}
$type = rtrim($foundPackage->package_type, 's');
$updatable = $this->gpm->{'is' . $type . 'Updatable'}($foundPackage->slug);
$installed = $this->gpm->{'is' . $type . 'Installed'}($foundPackage->slug);
// display current version if installed and different
if ($installed && $updatable) {
$local = $this->gpm->{'getInstalled'. $type}($foundPackage->slug);
$this->output->writeln('');
$this->output->writeln("Currently installed version: " . $local->version . "");
$this->output->writeln('');
}
// display changelog information
$questionHelper = $this->getHelper('question');
$question = new ConfirmationQuestion("Would you like to read the changelog? [y|N] ",
false);
$answer = $this->all_yes ? true : $questionHelper->ask($this->input, $this->output, $question);
if ($answer) {
$changelog = $foundPackage->changelog;
$this->output->writeln("");
foreach ($changelog as $version => $log) {
$title = $version . ' [' . $log['date'] . ']';
$content = preg_replace_callback('/\d\.\s\[\]\(#(.*)\)/', function ($match) {
return "\n" . ucfirst($match[1]) . ":";
}, $log['content']);
$this->output->writeln(''.$title.'');
$this->output->writeln(str_repeat('-', strlen($title)));
$this->output->writeln($content);
$this->output->writeln("");
$question = new ConfirmationQuestion("Press [ENTER] to continue or [q] to quit ", true);
$answer = $this->all_yes ? false : $questionHelper->ask($this->input, $this->output, $question);
if (!$answer) {
break;
}
$this->output->writeln("");
}
}
$this->output->writeln('');
if ($installed && $updatable) {
$this->output->writeln("You can update this package by typing:");
$this->output->writeln(" " . $this->argv . " update " . $foundPackage->slug . "");
} else {
$this->output->writeln("You can install this package by typing:");
$this->output->writeln(" " . $this->argv . " install " . $foundPackage->slug . "");
}
$this->output->writeln('');
}
}