From 37d449a8b525f323c712de0c8829ea5038f9a1e6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 12 Aug 2026 21:05:58 +0200 Subject: [PATCH] feat: allow specifying output format in unified sharing cli Signed-off-by: Robin Appelman --- apps/sharing/lib/Command/GetShares.php | 4 +++- apps/sharing/lib/Command/SharingBase.php | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/sharing/lib/Command/GetShares.php b/apps/sharing/lib/Command/GetShares.php index 215e6f2ca4123..6e4158eb55be7 100644 --- a/apps/sharing/lib/Command/GetShares.php +++ b/apps/sharing/lib/Command/GetShares.php @@ -55,7 +55,9 @@ public function execute(InputInterface $input, OutputInterface $output): int { $shares = $this->manager->getShares($this->accessContext, $filterSourceTypeClass, $filterSourceTypeValue, $lastShareID, $limit); $this->dbConnection->commit(); - $output->writeln(json_encode(Share::formatMultiple($this->registry, $this->l10nFactory, $this->urlGenerator, $this->userManager, $shares), JSON_THROW_ON_ERROR)); + + $data = Share::formatMultiple($this->registry, $this->l10nFactory, $this->urlGenerator, $this->userManager, $shares); + $this->writeArrayInOutputFormat($input, $output, $data); return Base::SUCCESS; } catch (Exception $exception) { $this->dbConnection->rollBack(); diff --git a/apps/sharing/lib/Command/SharingBase.php b/apps/sharing/lib/Command/SharingBase.php index b7395b52df1c6..a0a7829d255d9 100644 --- a/apps/sharing/lib/Command/SharingBase.php +++ b/apps/sharing/lib/Command/SharingBase.php @@ -21,13 +21,12 @@ use OCP\IURLGenerator; use OCP\IUserManager; use OCP\L10N\IFactory; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; -abstract class SharingBase extends Command { +abstract class SharingBase extends Base { public ShareAccessContext $accessContext; public function __construct( @@ -71,7 +70,10 @@ protected function wrapExecution(InputInterface $input, OutputInterface $output, $share = $closure(); $this->dbConnection->commit(); - $output->writeln(json_encode($share->format($this->registry, $this->l10nFactory, $this->urlGenerator, $this->userManager), JSON_THROW_ON_ERROR)); + + $data = $share->format($this->registry, $this->l10nFactory, $this->urlGenerator, $this->userManager); + $this->writeArrayInOutputFormat($input, $output, $data); + return Base::SUCCESS; } catch (Exception $exception) { $this->dbConnection->rollBack();