mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-30 05:34:49 +01:00
LSldapObject : add CLI show command
This commit is contained in:
parent
09e051a1e7
commit
7879ddf699
1 changed files with 63 additions and 0 deletions
|
@ -1872,6 +1872,61 @@ class LSldapObject {
|
||||||
}
|
}
|
||||||
return "<LdapObject (new)>";
|
return "<LdapObject (new)>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function cli_show($command_args) {
|
||||||
|
$objType = null;
|
||||||
|
$dn = null;
|
||||||
|
$raw_values = false;
|
||||||
|
foreach ($command_args as $arg) {
|
||||||
|
if ($arg == '-r' || $arg == '--raw-value')
|
||||||
|
$raw_values = true;
|
||||||
|
elseif (is_null($objType)) {
|
||||||
|
$objType = $arg;
|
||||||
|
}
|
||||||
|
elseif (is_null($dn)) {
|
||||||
|
$dn = $arg;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LScli :: usage("Invalid $arg parameter.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($objType) || is_null($dn))
|
||||||
|
LScli :: usage('You must provide LSobject type and DN.');
|
||||||
|
|
||||||
|
if (!LSsession :: loadLSobject($objType))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$obj = new $objType();
|
||||||
|
if (!$obj->loadData($dn)) {
|
||||||
|
LSlog :: fatal("Fail to load object $dn data from LDAP");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $obj -> _cli_show($raw_values);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function _cli_show($raw_values) {
|
||||||
|
echo $this -> type_name." (".($this -> dn?$this -> dn:'new').") :\n";
|
||||||
|
foreach ($this -> attrs as $attr_name => $attr) {
|
||||||
|
echo " - $attr_name :";
|
||||||
|
$values = ($raw_values?$attr->getValue():$attr->getDisplayValue());
|
||||||
|
if (empty($values)) {
|
||||||
|
echo " empty\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!is_array($values)) $values = array($values);
|
||||||
|
|
||||||
|
// Truncate values if too long
|
||||||
|
for ($i=0; $i < count($values); $i++)
|
||||||
|
if (strlen($values[$i]) > 70)
|
||||||
|
$values[$i] = substr($values[$i], 0, 65)."[...]";
|
||||||
|
echo (count($values) > 1?"\n - ":" ");
|
||||||
|
echo implode("\n - ", $values);
|
||||||
|
echo "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1995,3 +2050,11 @@ _("LSldapObject : Error during generating container DN : %{error}")
|
||||||
LSerror :: defineError('LSrelations_05',
|
LSerror :: defineError('LSrelations_05',
|
||||||
_("LSrelation : Some parameters are missing in the call of methods to handle standard relations (Method : %{meth}).")
|
_("LSrelation : Some parameters are missing in the call of methods to handle standard relations (Method : %{meth}).")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// LScli
|
||||||
|
LScli :: add_command(
|
||||||
|
'show',
|
||||||
|
array('LSldapObject', 'cli_show'),
|
||||||
|
'Show an LSobject',
|
||||||
|
'[object type] [dn] [-r|--raw-values]'
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in a new issue