Command Line Plugins
DokuWiki is meant to be used from a web browser, so nearly everything can be tuned through the web interface and you rarely need to edit a config file or run something from the console. However some times the console is a better solution to a problem than a web interface. Very long running processes are one example or things you may want to schedule through cron jobs.

DokuWiki comes with a few command line scripts by default in the bin directory. In the beginning those scripts did their argument parsing by themselves, later a simple frame work was introduced. This framework grew into it's own little library outside of DokuWiki.

This weekend I finally switched the DokuWiki internal framework to this library. This is in line with our goal to move non-DokuWiki specific code out into their own libraries to make them useful for more people and get valuable contributions from outside the DokuWiki community.

But just switching the CLI framework isn't what this post is about. I went a step further and made command line scripts the 8th plugin type next to syntax, action, admin, helper, renderer, remote and auth plugins. This means plugin authors now can easily add command line components to their plugins.

Plugin CLIs are accessed through a new script in bin, called bin/plugin.php - call it without arguments and it will show you all available CLI plugins. Give the plugin name (or sub component) as the first argument and it will be executed.

So how do you write a CLI plugin? As with all other plugins, you follow the naming structure and implement the required methods. For CLI plugins, those methods are setup() and main(). In the former you describe what your CLI does and which options and arguments it accepts. In the latter you execute the code based on those parameters.

Of course you can use all the usual plugin functionality like getConf() or getLang() within your plugin. You can also load your helper components to do the actual work for you.

The framework will automatically create a proper help screen and add a few default options.

The changes are currently waiting for feedback from the other developers and will soon be in the master branch.