Skip to content

Commit

Permalink
Modules\Module: improve provided metadata
Browse files Browse the repository at this point in the history
refs #4095
  • Loading branch information
Thomas-Gelf authored and majentsch committed May 28, 2014
1 parent 1b66504 commit 63f20e1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion application/clicommands/ModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function listAction()
if ($this->isVerbose) {
$dir = ' ' . $this->modules->getModuleDir($module);
} else {
$dir = $mod->getShortDescription();
$dir = $mod->getTitle();
}
printf(
"%-14s %-9s %-9s %s\n",
Expand Down
61 changes: 47 additions & 14 deletions library/Icinga/Application/Modules/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,23 @@ public function getVersion()
}

/**
* Get short description
* Get module description
*
* @return string
*/
public function getShortDescription()
public function getDescription()
{
return $this->metadata()->shortDescription;
return $this->metadata()->description;
}

/**
* Get module title (short description)
*
* @return string
*/
public function getTitle()
{
return $this->metadata()->title;
}

/**
Expand All @@ -308,7 +318,6 @@ public function getShortDescription()
*/
public function getDependencies()
{

return $this->metadata()->depends;
}

Expand All @@ -321,11 +330,11 @@ protected function metadata()
{
if ($this->metadata === null) {
$metadata = (object) array(
'name' => $this->getName(),
'version' => '0.0.0',
'shortDescription' => '',
'description' => '',
'depends' => array(),
'name' => $this->getName(),
'version' => '0.0.0',
'title' => null,
'description' => '',
'depends' => array(),
);

if (file_exists($this->metadataFile)) {
Expand All @@ -336,15 +345,21 @@ protected function metadata()
while (false !== ($line = fgets($fh))) {
$line = rtrim($line);

if ($key === 'description' && $line[0] === ' ') {
$metadata->{$key} .= "\n" . ltrim($line);
continue;
if ($key === 'description') {
if (empty($line)) {
$metadata->description .= "\n";
continue;
} elseif ($line[0] === ' ') {
$metadata->description .= $line;
continue;
}
}

list($key, $val) = preg_split('/:\s+/', $line, 2);
$key = lcfirst($key);

switch ($key) {

case 'depends':
if (strpos($val, ' ') === false) {
$metadata->depends[$val] = true;
Expand All @@ -361,16 +376,34 @@ protected function metadata()
}
}
break;

case 'description':
$metadata->shortDescription = $val;
// YES, no break here
if ($metadata->title === null) {
$metadata->title = $val;
} else {
$metadata->description = $val;
}
break;

default:
$metadata->{$key} = $val;

}
}
}

if ($metadata->title === null) {
$metadata->title = $this->getName();
}

if ($metadata->description === '') {
// TODO: Check whether the translation module is able to
// extract this
$metadata->description = t(
'This module has no description'
);
}

$this->metadata = $metadata;
}
return $this->metadata;
Expand Down

0 comments on commit 63f20e1

Please sign in to comment.