lib/Extension/CLIPlugin.php
, before called DokuWiki_CLI_Plugin
which is still available as aliasCLI (Command Line Interface) plugins give you an easy way to provide more DokuWiki features accessible from the command line. This is mostly useful as component in a larger plugin where certain functionality should be run from Cron jobs or by experienced Administrators only.
CLI plugins are based on the php-cli library, it's documentation might be an additional help.
Available CLI Plugins are listed. They can be installed via the Extension Manager.
DokuWiki comes with bin/plugin.php
. Call it without parameters to list all available CLI plugins. Call it with the name of the plugin as the first argument to call that plugin.
For the Example plugin below, call
./bin/plugin.php example -v
An CLI Plugin Example needs:
cli_plugin_example
lib/plugins/example/cli.php
.For full details of plugins and their files and how to create more CLI components refer to plugin file structure.
Inheriting from the dokuwiki\Extension\CLIPlugin
requires you to implement multiple methods in your class.
This method is passed an Options
object on which you should call multiple methods to configure the behavior of your CLI tool. This configures which arguments and parameters are accepted and required for your tool.
Refer to the Options documentation on the available methods.
This method is passed an Options
object from which you can get all the parsed arguments and parameters.
This is where you should call your main code. You might want to use a Helper Plugin here.
See common plugin functions for inherited functions available to all plugins. e.g. localisation, configuration and introspection.
<?php use dokuwiki\Extension\CLIPlugin; use splitbrain\phpcli\Options; class cli_plugin_example extends CLIPlugin { /** * register options and arguments * * @param Options $options */ protected function setup(Options $options) { $options->setHelp('A very minimal example that does nothing but print the plugin version info'); $options->registerOption('version', 'print version', 'v'); } /** * implement your code * * @param Options $options */ protected function main(Options $options) { if ($options->getOpt('version')) { $info = $this->getInfo(); // method available in all DokuWiki plugins $this->success($info['date']); } else { echo $options->help(); } } }
lib/Extension/CLIPlugin.php
, before called DokuWiki_CLI_Plugin
which is still available as alias