addCommands([ new PluginListCommand(), ]); } /** * @param string $pluginName * @return void */ public function setPluginName(string $pluginName): void { $this->pluginName = $pluginName; } /** * @return string */ public function getPluginName(): string { return $this->pluginName; } /** * @param InputInterface|null $input * @param OutputInterface|null $output * @return int * @throws Throwable */ public function run(InputInterface $input = null, OutputInterface $output = null): int { if (null === $input) { $argv = $_SERVER['argv'] ?? []; $bin = array_shift($argv); $this->pluginName = array_shift($argv); $argv = array_merge([$bin], $argv); $input = new ArgvInput($argv); } return parent::run($input, $output); } /** * @return void */ protected function init(): void { if ($this->initialized) { return; } parent::init(); if (null === $this->pluginName) { $this->setDefaultCommand('plugins:list'); return; } $grav = Grav::instance(); $grav->initializeCli(); /** @var Plugins $plugins */ $plugins = $grav['plugins']; $plugin = $this->pluginName ? $plugins::get($this->pluginName) : null; if (null === $plugin) { throw new NamespaceNotFoundException("Plugin \"{$this->pluginName}\" is not installed."); } if (!$plugin->enabled) { throw new NamespaceNotFoundException("Plugin \"{$this->pluginName}\" is not enabled."); } $this->setCommandLoader(new PluginCommandLoader($this->pluginName)); } }