Cli\Loader: allow injecting a module name

This helps those who prefer to create their own executables instead
of creating icingacli subcommands.

refs #6411
This commit is contained in:
Thomas Gelf 2014-06-04 23:04:11 +00:00
parent eadb6cb518
commit bdcec5a253
1 changed files with 17 additions and 2 deletions

View File

@ -109,6 +109,12 @@ class Loader
return $this->moduleName; return $this->moduleName;
} }
public function setModuleName($name)
{
$this->moduleName = $name;
return $this;
}
public function getCommandName() public function getCommandName()
{ {
return $this->commandName; return $this->commandName;
@ -180,7 +186,13 @@ class Loader
if (! $first) { if (! $first) {
return; return;
} }
$found = $this->resolveName($first);
if ($this->moduleName === null) {
$found = $this->resolveName($first);
} else {
$found = $this->moduleName;
$params->unshift($first);
}
if (! $found) { if (! $found) {
$msg = "There is no such module or command: '$first'"; $msg = "There is no such module or command: '$first'";
printf("%s: %s\n", $this->screen()->colorize('ERROR', 'red'), $msg); printf("%s: %s\n", $this->screen()->colorize('ERROR', 'red'), $msg);
@ -419,7 +431,10 @@ class Loader
{ {
if ($this->modules === null) { if ($this->modules === null) {
$this->modules = array(); $this->modules = array();
$this->modules = $this->app->getModuleManager()->listEnabledModules(); $this->modules = array_merge(
$this->app->getModuleManager()->listEnabledModules(),
$this->app->getModuleManager()->listLoadedModules()
);
sort($this->modules); sort($this->modules);
} }
return $this->modules; return $this->modules;