4 use dokuwiki\Extension\PluginController
;
5 use splitbrain\phpcli\CLI
;
6 use splitbrain\phpcli\Colors
;
7 use splitbrain\phpcli\Options
;
8 use dokuwiki\Extension\CLIPlugin
;
9 use splitbrain\phpcli\TableFormatter
;
11 if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__
. '/../') . '/');
12 define('NOSESSION', 1);
13 require_once(DOKU_INC
. 'inc/init.php');
15 class PluginCLI
extends CLI
18 * Register options and arguments on the given $options object
20 * @param Options $options
23 protected function setup(Options
$options)
25 $options->setHelp('Excecutes Plugin command line tools');
26 $options->registerArgument('plugin', 'The plugin CLI you want to run. Leave off to see list', false);
32 * Arguments and options have been parsed when this is run
34 * @param Options $options
37 protected function main(Options
$options)
40 $argv = $options->getArgs();
43 $plugin = $this->loadPlugin($argv[0]);
44 if ($plugin instanceof CLIPlugin
) {
47 $this->fatal('Command {cmd} not found.', ['cmd' => $argv[0]]);
50 echo $options->help();
56 * List available plugins
58 protected function listPlugins()
60 /** @var PluginController $plugin_controller */
61 global $plugin_controller;
65 echo $this->colors
->wrap('AVAILABLE PLUGINS:', Colors
::C_BROWN
);
68 $list = $plugin_controller->getList('cli');
71 echo $this->colors
->wrap(" No plugins providing CLI components available\n", Colors
::C_RED
);
73 $tf = new TableFormatter($this->colors
);
75 foreach ($list as $name) {
76 $plugin = $this->loadPlugin($name);
77 if (!$plugin instanceof CLIPlugin
) continue;
78 $info = $plugin->getInfo();
82 ['', $name, $info['desc']],
83 ['', Colors
::C_CYAN
, '']
90 * Instantiate a CLI plugin
93 * @return CLIPlugin|null
95 protected function loadPlugin($name)
97 if (plugin_isdisabled($name)) return null;
99 // execute the plugin CLI
100 $class = "cli_plugin_$name";
101 if (class_exists($class)) {
109 $cli = new PluginCLI();