diff --git a/bin/gpm b/bin/gpm index 9a5ad34c2..11d66ac99 100755 --- a/bin/gpm +++ b/bin/gpm @@ -34,6 +34,7 @@ $grav['themes']->init(); $app = new Application('Grav Package Manager', GRAV_VERSION); $app->addCommands(array( new \Grav\Console\Gpm\IndexCommand(), + new \Grav\Console\Gpm\VersionCommand(), new \Grav\Console\Gpm\InfoCommand(), new \Grav\Console\Gpm\InstallCommand(), new \Grav\Console\Gpm\UpdateCommand(), diff --git a/system/src/Grav/Console/Gpm/VersionCommand.php b/system/src/Grav/Console/Gpm/VersionCommand.php new file mode 100644 index 000000000..44b31efba --- /dev/null +++ b/system/src/Grav/Console/Gpm/VersionCommand.php @@ -0,0 +1,95 @@ +setName("version") + ->addOption( + 'force', + 'f', + InputOption::VALUE_NONE, + 'Force re-fetching the data from remote' + ) + ->addArgument( + 'package', + InputArgument::IS_ARRAY | InputArgument::OPTIONAL, + 'The package or packages that is desired to know the version of. By default and if not specified this would be grav' + ) + ->setDescription("Shows the version of an installed package. If available also shows pending updates.") + ->setHelp('The version command displays the current version of a package installed and, if available, the available version of pending updates'); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->setupConsole($input, $output); + + $this->gpm = new GPM($this->input->getOption('force')); + $packages = $this->input->getArgument('package'); + + if (!count($packages)) { + $packages = ['grav']; + } + + foreach ($packages as $package) { + $package = strtolower($package); + $name = null; + $version = null; + $updatable = false; + + if ($package == 'grav') { + $name = 'Grav'; + $version = GRAV_VERSION; + $upgrader = new Upgrader(); + + if ($upgrader->isUpgradable()) { + $updatable = ' [upgradable: v' . $upgrader->getRemoteVersion() . ']'; + } + + } else { + if ($installed = $this->gpm->findPackage($package)) { + $name = $installed->name; + $version = $installed->version; + + if ($this->gpm->isUpdatable($package)) { + $updatable = ' [updatable: v' . $installed->available . ']'; + } + } + } + + $updatable = $updatable ?: ''; + $this->output->writeln('You are running ' . $name . ' v' . $version . '' . $updatable); + } + } +}