CLI fix for --watch, hide autocomplete documentation

This commit is contained in:
Thomas Gelf 2014-02-14 13:19:56 +00:00
parent 3bb2206753
commit 6096b23a76
4 changed files with 13 additions and 4 deletions

View File

@ -149,12 +149,12 @@ class Cli extends ApplicationBootstrap
$loader = new Loader($this); $loader = new Loader($this);
$loader->parseParams(); $loader->parseParams();
$screen = Screen::instance(); $screen = Screen::instance();
while (true) { while (true) {
Benchmark::measure('Watch mode - loop begins'); Benchmark::measure('Watch mode - loop begins');
ob_start(); ob_start();
echo $screen->clear();
$params = clone($this->params); $params = clone($this->params);
$loader->dispatch(); $loader->dispatch($params);
Benchmark::measure('Dispatch done'); Benchmark::measure('Dispatch done');
if ($this->showBenchmark) { if ($this->showBenchmark) {
Benchmark::dump(); Benchmark::dump();
@ -163,7 +163,6 @@ class Cli extends ApplicationBootstrap
$out = ob_get_contents(); $out = ob_get_contents();
ob_end_clean(); ob_end_clean();
echo $screen->clear() . $out; echo $screen->clear() . $out;
$this->params = $params;
sleep($this->watchTimeout); sleep($this->watchTimeout);
} }
} }

View File

@ -4,6 +4,7 @@ namespace Icinga\Cli;
use Icinga\Cli\Screen; use Icinga\Cli\Screen;
use Icinga\Util\Translator; use Icinga\Util\Translator;
use Icinga\Cli\Params;
use Icinga\Application\ApplicationBootstrap as App; use Icinga\Application\ApplicationBootstrap as App;
use Exception; use Exception;
@ -38,6 +39,11 @@ abstract class Command
} }
} }
public function setParams(Params $params)
{
$this->params = $params;
}
public function hasRemainingParams() public function hasRemainingParams()
{ {
return $this->params->count() > 0; return $this->params->count() > 0;

View File

@ -35,6 +35,7 @@ class Documentation
$d = "USAGE: icingaweb [module] <command> [action] [options]\n\n" $d = "USAGE: icingaweb [module] <command> [action] [options]\n\n"
. "Available commands:\n\n"; . "Available commands:\n\n";
foreach ($this->loader->listCommands() as $command) { foreach ($this->loader->listCommands() as $command) {
if ($command === 'autocomplete') continue;
$obj = $this->loader->getCommandInstance($command); $obj = $this->loader->getCommandInstance($command);
$d .= sprintf( $d .= sprintf(
" %-14s %s\n", " %-14s %s\n",

View File

@ -224,7 +224,7 @@ class Loader
$this->dispatch(); $this->dispatch();
} }
public function dispatch() public function dispatch(Params $overrideParams = null)
{ {
if ($this->commandName === null) { if ($this->commandName === null) {
echo $this->docs()->usage($this->moduleName); echo $this->docs()->usage($this->moduleName);
@ -244,6 +244,9 @@ class Loader
} else { } else {
$obj = $this->getCommandInstance($this->commandName); $obj = $this->getCommandInstance($this->commandName);
} }
if ($overrideParams !== null) {
$obj->setParams($overrideParams);
}
$obj->init(); $obj->init();
return $obj->{$this->actionName . 'Action'}(); return $obj->{$this->actionName . 'Action'}();
} catch (Exception $e) { } catch (Exception $e) {