示例#1
0
 /**
  * @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<green>' . $upgrader->getRemoteVersion() . '</green>]';
             }
         } 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<green>' . $installed->available . '</green>]';
                 }
             }
         }
         $updatable = $updatable ?: '';
         if ($installed || $package == 'grav') {
             $this->output->writeln('You are running <white>' . $name . '</white> v<cyan>' . $version . '</cyan>' . $updatable);
         } else {
             $this->output->writeln('Package <red>' . $package . '</red> not found');
         }
     }
 }
 /**
  * @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');
     $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<green>' . $upgrader->getRemoteVersion() . '</green>]';
             }
         } else {
             if ($installed = $this->gpm->findPackage($package)) {
                 $name = $installed->name;
                 $version = $installed->version;
                 if ($this->gpm->isUpdatable($package)) {
                     $updatable = ' [updatable: v<green>' . $installed->available . '</green>]';
                 }
             }
         }
         $updatable = $updatable ?: '';
         if ($installed || $package == 'grav') {
             $this->output->writeln('You are running <white>' . $name . '</white> v<cyan>' . $version . '</cyan>' . $updatable);
         } else {
             $this->output->writeln('Package <red>' . $package . '</red> not found');
         }
     }
 }