From 9c66bf6dc3ca29ac52f6fd83ff0d05edafb917b3 Mon Sep 17 00:00:00 2001 From: Lucas Azevedo Date: Fri, 25 Aug 2023 11:13:34 -0300 Subject: [PATCH] Use table output for list command Signed-off-by: Lucas Azevedo --- core/Command/User/AuthTokens/ListCommand.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/Command/User/AuthTokens/ListCommand.php b/core/Command/User/AuthTokens/ListCommand.php index 6739e8b4648..97e94f29f92 100644 --- a/core/Command/User/AuthTokens/ListCommand.php +++ b/core/Command/User/AuthTokens/ListCommand.php @@ -61,18 +61,24 @@ class ListCommand extends Base { $tokens = $this->tokenProvider->getTokenByUser($user->getUID()); - $data = array_map(function (IToken $token): mixed { - $filtered = [ + $tokens = array_map(function (IToken $token) use ($input): mixed { + $sensitive = [ 'password', 'password_hash', 'token', 'public_key', 'private_key', ]; - return array_diff_key($token->jsonSerialize(), array_flip($filtered)); + $data = array_diff_key($token->jsonSerialize(), array_flip($sensitive)); + + if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { + $data['scope'] = implode(', ', array_keys(array_filter($data['scope']))); + } + + return $data; }, $tokens); - $this->writeArrayInOutputFormat($input, $output, $data); + $this->writeTableInOutputFormat($input, $output, $tokens); return 0; } -- 2.39.5