mirror of
https://github.com/cosmocode/dokuwiki-plugin-statdisplay.git
synced 2025-07-23 00:51:10 +00:00
add CLI to (re)parse the log
This commit is contained in:
56
cli.php
Normal file
56
cli.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use dokuwiki\Extension\CLIPlugin;
|
||||
use splitbrain\phpcli\Options;
|
||||
|
||||
class cli_plugin_statdisplay extends CLIPlugin
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setup(Options $options)
|
||||
{
|
||||
$options->setHelp('Control the statdisplay plugin');
|
||||
$options->registerCommand('parse', 'Parse and analyse the log file');
|
||||
$options->registerOption('clear', 'Drop all previously parsed log data and reparse the whole log file', 'c',
|
||||
false, 'parse');
|
||||
$options->registerOption('lines', 'Number of lines to read per iteration', 'l', 'lines', 'parse');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function main(Options $options)
|
||||
{
|
||||
switch($options->getCmd()) {
|
||||
case 'parse':
|
||||
$this->parseData(
|
||||
$this->options->getOpt('clear'),
|
||||
(int) $this->options->getOpt('lines', $this->getConf('lines'))
|
||||
);
|
||||
break;
|
||||
default:
|
||||
echo $this->options->help();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the log data
|
||||
*
|
||||
* @param bool $clear
|
||||
*/
|
||||
protected function parseData($clear, $maxlines)
|
||||
{
|
||||
/** @var helper_plugin_statdisplay_log $helper */
|
||||
$helper = plugin_load('helper', 'statdisplay_log');
|
||||
|
||||
if($clear) {
|
||||
$helper->resetLogCache();
|
||||
}
|
||||
|
||||
do {
|
||||
$this->info(sprintf('%.2f%%', $helper->progress()));
|
||||
} while ($helper->parseLogData($maxlines));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user