diff options
author | Christopher Ng <chrng8@gmail.com> | 2023-08-01 14:58:57 -0700 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2023-08-08 16:29:12 -0700 |
commit | a377862ed13fb03d7cba8b685d92f723373400e3 (patch) | |
tree | dc1dd5845b0a0fa7b519ae56e0d278042e58e6b4 | |
parent | 0ffb3672fef8f325d5e5de87bf3be4ad81586d49 (diff) | |
download | nextcloud-server-a377862ed13fb03d7cba8b685d92f723373400e3.tar.gz nextcloud-server-a377862ed13fb03d7cba8b685d92f723373400e3.zip |
enh: add json output to command
Signed-off-by: Christopher Ng <chrng8@gmail.com>
(cherry picked from commit e320166b151ef308a9a289c77bea2a4e50b4e994)
-rw-r--r-- | apps/files_reminders/lib/Command/ListCommand.php | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/apps/files_reminders/lib/Command/ListCommand.php b/apps/files_reminders/lib/Command/ListCommand.php index b066c6ed8cf..3f3ce13b857 100644 --- a/apps/files_reminders/lib/Command/ListCommand.php +++ b/apps/files_reminders/lib/Command/ListCommand.php @@ -33,6 +33,7 @@ use OCA\FilesReminders\Service\ReminderService; use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -52,6 +53,13 @@ class ListCommand extends Base { 'user', InputArgument::OPTIONAL, 'list reminders for user', + ) + ->addOption( + 'output', + null, + InputOption::VALUE_OPTIONAL, + 'Output format (plain, json or json_pretty, default is plain)', + $this->defaultOutputFormat, ); } @@ -74,20 +82,37 @@ class ListCommand extends Base { return 0; } - $io->table( - ['User Id', 'Path', 'Due Date', 'Updated At', 'Created At', 'Notified'], - array_map( - fn (RichReminder $reminder) => [ - $reminder->getUserId(), - $reminder->getNode()->getPath(), - $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601 - $reminder->getUpdatedAt()->format(DateTimeInterface::ATOM), // ISO 8601 - $reminder->getCreatedAt()->format(DateTimeInterface::ATOM), // ISO 8601 - $reminder->getNotified() ? 'true' : 'false', - ], - $reminders, - ) - ); - return 0; + $outputOption = $input->getOption('output'); + switch ($outputOption) { + case static::OUTPUT_FORMAT_JSON: + case static::OUTPUT_FORMAT_JSON_PRETTY: + $this->writeArrayInOutputFormat( + $input, + $io, + array_map( + fn (RichReminder $reminder) => $reminder->jsonSerialize(), + $reminders, + ), + '', + ); + return 0; + default: + $io->table( + ['User Id', 'File Id', 'Path', 'Due Date', 'Updated At', 'Created At', 'Notified'], + array_map( + fn (RichReminder $reminder) => [ + $reminder->getUserId(), + $reminder->getFileId(), + $reminder->getNode()->getPath(), + $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601 + $reminder->getUpdatedAt()->format(DateTimeInterface::ATOM), // ISO 8601 + $reminder->getCreatedAt()->format(DateTimeInterface::ATOM), // ISO 8601 + $reminder->getNotified() ? 'true' : 'false', + ], + $reminders, + ), + ); + return 0; + } } } |