4 use dokuwiki\Extension\PluginController
;
5 use splitbrain\phpcli\CLI
;
6 use splitbrain\phpcli\Colors
;
7 use splitbrain\phpcli\Options
;
9 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__
) . '/../') . '/');
10 define('NOSESSION', 1);
11 require_once(DOKU_INC
. 'inc/init.php');
13 class PluginCLI
extends CLI
{
16 * Register options and arguments on the given $options object
18 * @param Options $options
21 protected function setup(Options
$options) {
22 $options->setHelp('Excecutes Plugin command line tools');
23 $options->registerArgument('plugin', 'The plugin CLI you want to run. Leave off to see list', false);
29 * Arguments and options have been parsed when this is run
31 * @param Options $options
34 protected function main(Options
$options) {
36 $argv = $options->getArgs();
39 $plugin = $this->loadPlugin($argv[0]);
40 if($plugin !== null) {
43 $this->fatal('Command {cmd} not found.', ['cmd' => $argv[0]]);
46 echo $options->help();
52 * List available plugins
54 protected function listPlugins() {
55 /** @var PluginController $plugin_controller */
56 global $plugin_controller;
60 echo $this->colors
->wrap('AVAILABLE PLUGINS:', Colors
::C_BROWN
);
63 $list = $plugin_controller->getList('cli');
66 echo $this->colors
->wrap(" No plugins providing CLI components available\n", Colors
::C_RED
);
68 $tf = new \splitbrain\phpcli\
TableFormatter($this->colors
);
70 foreach($list as $name) {
71 $plugin = $this->loadPlugin($name);
72 if($plugin === null) continue;
73 $info = $plugin->getInfo();
77 ['', $name, $info['desc']],
78 ['', Colors
::C_CYAN
, '']
86 * Instantiate a CLI plugin
89 * @return \dokuwiki\Extension\CLIPlugin|null
91 protected function loadPlugin($name) {
92 // execute the plugin CLI
93 $class = "cli_plugin_$name";
94 if(class_exists($class)) {
102 $cli = new PluginCLI();