lib/plugins/cli.php
Table of Contents
CLI Plugins
CLI (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.
Executing CLI Plugins
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
Synopsis
An CLI Plugin Example needs:
- class name
cli_plugin_example
- which extends DokuWiki_CLI_Plugin1).
- to be stored in a file
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.
Required Implementation
Inheriting from the DokuWiki_CLI_Plugin
requires you to implement multiple methods in your class.
setup()
This method is passed an Option
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.
main()
This method is passed an Option
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.
Example
if(!defined('DOKU_INC')) die(); use splitbrain\phpcli\Options; class cli_plugin_example extends DokuWiki_CLI_Plugin { // register options and arguments 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 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(); } } }