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'); } /** * @return int|null|void */ protected function serve() { $this->gpm = new GPM($this->input->getOption('force')); $packages = $this->input->getArgument('package'); $installed = false; 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 { // get currently installed version $locator = \Grav\Common\Grav::instance()['locator']; $blueprints_path = $locator->findResource('plugins://' . $package . DS . 'blueprints.yaml'); if (!file_exists($blueprints_path)) { // theme? $blueprints_path = $locator->findResource('themes://' . $package . DS . 'blueprints.yaml'); if (!file_exists($blueprints_path)) { continue; } } $package_yaml = Yaml::parse(file_get_contents($blueprints_path)); $version = $package_yaml['version']; if (!$version) { continue; } $installed = $this->gpm->findPackage($package); if ($installed) { $name = $installed->name; if ($this->gpm->isUpdatable($package)) { $updatable = ' [updatable: v' . $installed->available . ']'; } } } $updatable = $updatable ?: ''; if ($installed || $package == 'grav') { $this->output->writeln('You are running ' . $name . ' v' . $version . '' . $updatable); } else { $this->output->writeln('Package ' . $package . ' not found'); } } } }