[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 #!/usr/bin/env php 2 <?php 3 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; 10 11 if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/'); 12 define('NOSESSION', 1); 13 require_once (DOKU_INC . 'inc/init.php'); 14 15 class PluginCLI extends CLI 16 { 17 /** 18 * Register options and arguments on the given $options object 19 * 20 * @param Options $options 21 * @return void 22 */ 23 protected function setup(Options $options) 24 { 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); 27 } 28 29 /** 30 * Your main program 31 * 32 * Arguments and options have been parsed when this is run 33 * 34 * @param Options $options 35 * @return void 36 */ 37 protected function main(Options $options) 38 { 39 global $argv; 40 $argv = $options->getArgs(); 41 42 if ($argv) { 43 $plugin = $this->loadPlugin($argv[0]); 44 if ($plugin instanceof CLIPlugin) { 45 $plugin->run(); 46 } else { 47 $this->fatal('Command {cmd} not found.', ['cmd' => $argv[0]]); 48 } 49 } else { 50 echo $options->help(); 51 $this->listPlugins(); 52 } 53 } 54 55 /** 56 * List available plugins 57 */ 58 protected function listPlugins() 59 { 60 /** @var PluginController $plugin_controller */ 61 global $plugin_controller; 62 63 echo "\n"; 64 echo "\n"; 65 echo $this->colors->wrap('AVAILABLE PLUGINS:', Colors::C_BROWN); 66 echo "\n"; 67 68 $list = $plugin_controller->getList('cli'); 69 sort($list); 70 if ($list === []) { 71 echo $this->colors->wrap(" No plugins providing CLI components available\n", Colors::C_RED); 72 } else { 73 $tf = new TableFormatter($this->colors); 74 75 foreach ($list as $name) { 76 $plugin = $this->loadPlugin($name); 77 if (!$plugin instanceof CLIPlugin) continue; 78 $info = $plugin->getInfo(); 79 80 echo $tf->format( 81 [2, '30%', '*'], 82 ['', $name, $info['desc']], 83 ['', Colors::C_CYAN, ''] 84 ); 85 } 86 } 87 } 88 89 /** 90 * Instantiate a CLI plugin 91 * 92 * @param string $name 93 * @return CLIPlugin|null 94 */ 95 protected function loadPlugin($name) 96 { 97 if (plugin_isdisabled($name)) return null; 98 99 // execute the plugin CLI 100 $class = "cli_plugin_$name"; 101 if (class_exists($class)) { 102 return new $class(); 103 } 104 return null; 105 } 106 } 107 108 // Main 109 $cli = new PluginCLI(); 110 $cli->run();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body