diff options
Diffstat (limited to 'bin/plugin.php')
-rwxr-xr-x | bin/plugin.php | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/bin/plugin.php b/bin/plugin.php index 62c2f55ee..99c496bf7 100755 --- a/bin/plugin.php +++ b/bin/plugin.php @@ -5,20 +5,23 @@ use dokuwiki\Extension\PluginController; use splitbrain\phpcli\CLI; use splitbrain\phpcli\Colors; use splitbrain\phpcli\Options; +use dokuwiki\Extension\CLIPlugin; +use splitbrain\phpcli\TableFormatter; -if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/'); +if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/'); define('NOSESSION', 1); require_once(DOKU_INC . 'inc/init.php'); -class PluginCLI extends CLI { - +class PluginCLI extends CLI +{ /** * Register options and arguments on the given $options object * * @param Options $options * @return void */ - protected function setup(Options $options) { + protected function setup(Options $options) + { $options->setHelp('Excecutes Plugin command line tools'); $options->registerArgument('plugin', 'The plugin CLI you want to run. Leave off to see list', false); } @@ -31,13 +34,14 @@ class PluginCLI extends CLI { * @param Options $options * @return void */ - protected function main(Options $options) { + protected function main(Options $options) + { global $argv; $argv = $options->getArgs(); - if($argv) { + if ($argv) { $plugin = $this->loadPlugin($argv[0]); - if($plugin !== null) { + if ($plugin instanceof CLIPlugin) { $plugin->run(); } else { $this->fatal('Command {cmd} not found.', ['cmd' => $argv[0]]); @@ -51,7 +55,8 @@ class PluginCLI extends CLI { /** * List available plugins */ - protected function listPlugins() { + protected function listPlugins() + { /** @var PluginController $plugin_controller */ global $plugin_controller; @@ -62,21 +67,20 @@ class PluginCLI extends CLI { $list = $plugin_controller->getList('cli'); sort($list); - if(!count($list)) { + if ($list === []) { echo $this->colors->wrap(" No plugins providing CLI components available\n", Colors::C_RED); } else { - $tf = new \splitbrain\phpcli\TableFormatter($this->colors); + $tf = new TableFormatter($this->colors); - foreach($list as $name) { + foreach ($list as $name) { $plugin = $this->loadPlugin($name); - if($plugin === null) continue; + if (!$plugin instanceof CLIPlugin) continue; $info = $plugin->getInfo(); echo $tf->format( [2, '30%', '*'], ['', $name, $info['desc']], ['', Colors::C_CYAN, ''] - ); } } @@ -86,14 +90,15 @@ class PluginCLI extends CLI { * Instantiate a CLI plugin * * @param string $name - * @return \dokuwiki\Extension\CLIPlugin|null + * @return CLIPlugin|null */ - protected function loadPlugin($name) { - if(plugin_isdisabled($name)) return null; + protected function loadPlugin($name) + { + if (plugin_isdisabled($name)) return null; // execute the plugin CLI $class = "cli_plugin_$name"; - if(class_exists($class)) { + if (class_exists($class)) { return new $class(); } return null; |