aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_reminders/lib
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2023-08-01 14:58:57 -0700
committerChristopher Ng <chrng8@gmail.com>2023-08-03 15:30:11 -0700
commite320166b151ef308a9a289c77bea2a4e50b4e994 (patch)
treeb6a4574bb48588b68042d082d261e05049873129 /apps/files_reminders/lib
parent113d061919de4bb0c88fbf0f44d006e0c8717d6c (diff)
downloadnextcloud-server-e320166b151ef308a9a289c77bea2a4e50b4e994.tar.gz
nextcloud-server-e320166b151ef308a9a289c77bea2a4e50b4e994.zip
enh: add json output to command
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/files_reminders/lib')
-rw-r--r--apps/files_reminders/lib/Command/ListCommand.php55
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;
+ }
}
}