summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorJohannes Leuker <j.leuker@hosting.de>2021-03-23 15:10:00 +0100
committerJohannes Leuker <j.leuker@hosting.de>2021-03-31 12:36:22 +0200
commit9660a3fa90b122e098ffa1eff44875b9b12cb95e (patch)
treee13199865678c4d2623fd49d1b96da446922bac2 /apps/user_ldap
parent89cf1cb33a25952cd1098cf4f2d9919f20a365a2 (diff)
downloadnextcloud-server-9660a3fa90b122e098ffa1eff44875b9b12cb95e.tar.gz
nextcloud-server-9660a3fa90b122e098ffa1eff44875b9b12cb95e.zip
Add json, yaml output options to ldap:show-config
Signed-off-by: Johannes Leuker <j.leuker@hosting.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/Command/ShowConfig.php56
1 files changed, 41 insertions, 15 deletions
diff --git a/apps/user_ldap/lib/Command/ShowConfig.php b/apps/user_ldap/lib/Command/ShowConfig.php
index 99180bd7996..6b285eb8afc 100644
--- a/apps/user_ldap/lib/Command/ShowConfig.php
+++ b/apps/user_ldap/lib/Command/ShowConfig.php
@@ -28,16 +28,16 @@
namespace OCA\User_LDAP\Command;
+use OC\Core\Command\Base;
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\Helper;
-use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-class ShowConfig extends Command {
+class ShowConfig extends Base {
/** @var \OCA\User_LDAP\Helper */
protected $helper;
@@ -64,6 +64,13 @@ class ShowConfig extends Command {
InputOption::VALUE_NONE,
'show ldap bind password'
)
+ ->addOption(
+ 'output',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output format (table, plain, json or json_pretty, default is table)',
+ 'table'
+ )
;
}
@@ -80,36 +87,55 @@ class ShowConfig extends Command {
$configIDs = $availableConfigs;
}
- $this->renderConfigs($configIDs, $output, $input->getOption('show-password'));
+ $this->renderConfigs($configIDs, $input, $output);
return 0;
}
/**
* prints the LDAP configuration(s)
* @param string[] configID(s)
+ * @param InputInterface $input
* @param OutputInterface $output
- * @param bool $withPassword Set to TRUE to show plaintext passwords in output
*/
- protected function renderConfigs($configIDs, $output, $withPassword) {
+ protected function renderConfigs($configIDs, $input, $output) {
+ $renderTable = $input->getOption('output') === 'table' or $input->getOption('output') === null;
+ $showPassword = $input->getOption('show-password');
+
+ $configs = [];
foreach ($configIDs as $id) {
$configHolder = new Configuration($id);
$configuration = $configHolder->getConfiguration();
ksort($configuration);
- $table = new Table($output);
- $table->setHeaders(['Configuration', $id]);
$rows = [];
- foreach ($configuration as $key => $value) {
- if ($key === 'ldapAgentPassword' && !$withPassword) {
- $value = '***';
+ if ($renderTable) {
+ foreach ($configuration as $key => $value) {
+ if (is_array($value)) {
+ $value = implode(';', $value);
+ }
+ if ($key === 'ldapAgentPassword' && !$showPassword) {
+ $rows[] = [$key, '***'];
+ } else {
+ $rows[] = [$key, $value];
+ }
}
- if (is_array($value)) {
- $value = implode(';', $value);
+ $table = new Table($output);
+ $table->setHeaders(['Configuration', $id]);
+ $table->setRows($rows);
+ $table->render();
+ } else {
+ foreach ($configuration as $key => $value) {
+ if ($key === 'ldapAgentPassword' && !$showPassword) {
+ $rows[$key] = '***';
+ } else {
+ $rows[$key] = $value;
+ }
}
- $rows[] = [$key, $value];
+ $configs[$id] = $rows;
}
- $table->setRows($rows);
- $table->render();
+ }
+ if (!$renderTable) {
+ $this->writeArrayInOutputFormat($input, $output, $configs);
}
}
}