Skip to content
Snippets Groups Projects
Commit 909b31ea authored by Robin Appelman's avatar Robin Appelman
Browse files

use common --output option

parent f5cdd27b
No related merge requests found
...@@ -21,11 +21,10 @@ ...@@ -21,11 +21,10 @@
namespace OCA\Files_External\Command; namespace OCA\Files_External\Command;
use OC\Core\Command\Base;
use OCA\Files_external\Lib\StorageConfig; use OCA\Files_external\Lib\StorageConfig;
use OCA\Files_external\Service\GlobalStoragesService; use OCA\Files_external\Service\GlobalStoragesService;
use OCA\Files_external\Service\UserStoragesService; use OCA\Files_external\Service\UserStoragesService;
use OCP\Files\IRootFolder;
use OCP\IUserBackend;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
...@@ -36,7 +35,7 @@ use Symfony\Component\Console\Input\InputInterface; ...@@ -36,7 +35,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class ListCommand extends Command { class ListCommand extends Base {
/** /**
* @var GlobalStoragesService * @var GlobalStoragesService
*/ */
...@@ -73,8 +72,8 @@ class ListCommand extends Command { ...@@ -73,8 +72,8 @@ class ListCommand extends Command {
'user_id', 'user_id',
InputArgument::OPTIONAL, InputArgument::OPTIONAL,
'user id to list the personal mounts for, if no user is provided admin mounts will be listed' 'user id to list the personal mounts for, if no user is provided admin mounts will be listed'
) );
->addOption('json', null, InputOption::VALUE_NONE, 'use json output instead of a human-readable array'); parent::configure();
} }
protected function execute(InputInterface $input, OutputInterface $output) { protected function execute(InputInterface $input, OutputInterface $output) {
...@@ -109,7 +108,8 @@ class ListCommand extends Command { ...@@ -109,7 +108,8 @@ class ListCommand extends Command {
$headers[] = 'Applicable Groups'; $headers[] = 'Applicable Groups';
} }
if ($input->getOption('json')) { $outputType = $input->getOption('output');
if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
$keys = array_map(function ($header) { $keys = array_map(function ($header) {
return strtolower(str_replace(' ', '_', $header)); return strtolower(str_replace(' ', '_', $header));
}, $headers); }, $headers);
...@@ -130,7 +130,11 @@ class ListCommand extends Command { ...@@ -130,7 +130,11 @@ class ListCommand extends Command {
return array_combine($keys, $values); return array_combine($keys, $values);
}, $mounts); }, $mounts);
$output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT)); if ($outputType === self::OUTPUT_FORMAT_JSON) {
$output->writeln(json_encode(array_values($pairs)));
} else {
$output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT));
}
} else { } else {
$defaultMountOptions = [ $defaultMountOptions = [
'encrypt' => true, 'encrypt' => true,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment