DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

Our Privacy Policy

devel:cli_plugins

CLI Plugins

CLI (Command Line Interface) plugins give you an easy way to provide 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.

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 auth_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

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();
        }
    }
}
1)
defined in lib/plugins/cli.php
devel/cli_plugins.txt · Last modified: 2018-04-25 16:27 by andi