From 6096b23a763f84d1648822c7d941a57c6ae98bb0 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 14 Feb 2014 13:19:56 +0000 Subject: [PATCH] CLI fix for --watch, hide autocomplete documentation --- library/Icinga/Application/Cli.php | 5 ++--- library/Icinga/Cli/Command.php | 6 ++++++ library/Icinga/Cli/Documentation.php | 1 + library/Icinga/Cli/Loader.php | 5 ++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Application/Cli.php b/library/Icinga/Application/Cli.php index ee61605df..95b841b66 100644 --- a/library/Icinga/Application/Cli.php +++ b/library/Icinga/Application/Cli.php @@ -149,12 +149,12 @@ class Cli extends ApplicationBootstrap $loader = new Loader($this); $loader->parseParams(); $screen = Screen::instance(); + while (true) { Benchmark::measure('Watch mode - loop begins'); ob_start(); - echo $screen->clear(); $params = clone($this->params); - $loader->dispatch(); + $loader->dispatch($params); Benchmark::measure('Dispatch done'); if ($this->showBenchmark) { Benchmark::dump(); @@ -163,7 +163,6 @@ class Cli extends ApplicationBootstrap $out = ob_get_contents(); ob_end_clean(); echo $screen->clear() . $out; - $this->params = $params; sleep($this->watchTimeout); } } diff --git a/library/Icinga/Cli/Command.php b/library/Icinga/Cli/Command.php index 6a977760e..46564fe28 100644 --- a/library/Icinga/Cli/Command.php +++ b/library/Icinga/Cli/Command.php @@ -4,6 +4,7 @@ namespace Icinga\Cli; use Icinga\Cli\Screen; use Icinga\Util\Translator; +use Icinga\Cli\Params; use Icinga\Application\ApplicationBootstrap as App; use Exception; @@ -38,6 +39,11 @@ abstract class Command } } + public function setParams(Params $params) + { + $this->params = $params; + } + public function hasRemainingParams() { return $this->params->count() > 0; diff --git a/library/Icinga/Cli/Documentation.php b/library/Icinga/Cli/Documentation.php index b868cae83..b9944ee06 100644 --- a/library/Icinga/Cli/Documentation.php +++ b/library/Icinga/Cli/Documentation.php @@ -35,6 +35,7 @@ class Documentation $d = "USAGE: icingaweb [module] [action] [options]\n\n" . "Available commands:\n\n"; foreach ($this->loader->listCommands() as $command) { + if ($command === 'autocomplete') continue; $obj = $this->loader->getCommandInstance($command); $d .= sprintf( " %-14s %s\n", diff --git a/library/Icinga/Cli/Loader.php b/library/Icinga/Cli/Loader.php index c93b35016..ceef6b851 100644 --- a/library/Icinga/Cli/Loader.php +++ b/library/Icinga/Cli/Loader.php @@ -224,7 +224,7 @@ class Loader $this->dispatch(); } - public function dispatch() + public function dispatch(Params $overrideParams = null) { if ($this->commandName === null) { echo $this->docs()->usage($this->moduleName); @@ -244,6 +244,9 @@ class Loader } else { $obj = $this->getCommandInstance($this->commandName); } + if ($overrideParams !== null) { + $obj->setParams($overrideParams); + } $obj->init(); return $obj->{$this->actionName . 'Action'}(); } catch (Exception $e) {