addOption("enable", null, InputOption::VALUE_REQUIRED, "Enable (symlink) a plugin"); $this->addOption("disable", null, InputOption::VALUE_REQUIRED, "Disable (remove) a plugin"); $this->addOption("force", "f", InputOption::VALUE_NONE, "Remove a plugin even if not a symlink"); } protected function execute(InputInterface $input, OutputInterface $output) { $env = $this->getEnvironment(); $app = $this->getApplication(); $globalPlugins = getenv("SPARK_PLUGINS"); $localPlugins = $env->getConfigDirectory()."/plugins"; $globalPluginList = glob($globalPlugins."/*"); $globalBasePluginList = array_map("basename", $globalPluginList); $localPluginList = array_map("basename", glob($localPlugins."/*")); if ($plugin = $input->getOption("enable")) { if (in_array($plugin, $localPluginList)) { $output->writeln("Plugin {$plugin} already enabled!"); return Command::SUCCESS; } if (!in_array($plugin, $globalBasePluginList)) { $output->writeln("No such plugin {$plugin}"); return Command::FAILURE; } symlink($globalPlugins."/".$plugin, $localPlugins."/".$plugin); $output->writeln("Enabled plugin {$plugin}!"); return Command::SUCCESS; } elseif ($plugin = $input->getOption("disable")) { $force = $input->getOption("force"); if (!in_array($plugin, $localPluginList)) { $output->writeln("Plugin {$plugin} not enabled!"); return Command::FAILURE; } if (!is_link($localPlugins."/".$plugin) && !$force) { $output->writeln("Plugin is not a symlink and --force not specified"); return Command::FAILURE; } elseif (is_link($localPlugins."/".$plugin)) { unlink($localPlugins."/".$plugin); $output->writeln("Disabled plugin {$plugin}!"); return Command::SUCCESS; } } foreach ($globalPluginList as $plugin) { if (!is_dir($plugin)) continue; if (!file_exists($plugin."/sparkplug.php")) continue; $head = (file($plugin."/sparkplug.php", FILE_IGNORE_NEW_LINES)[0])??null; if (str_contains($head, "//")) { $json = "{" . substr($head, strpos($head, "//") + 3) . "}"; $info = json_decode($json)??object(); } else { $info = object(); } $installed = in_array(basename($plugin), $localPluginList); $badge = ($installed)?"\u{2714}":"\u{25cc}"; $output->writeln(sprintf(" %s %-20s %s", $badge, ($installed?"#0ff":"#088"), basename($plugin), $info->name??null)); } return Command::SUCCESS; } }