diff options
author | Git'Fellow <12234510+solracsf@users.noreply.github.com> | 2024-10-28 18:47:18 +0100 |
---|---|---|
committer | Git'Fellow <12234510+solracsf@users.noreply.github.com> | 2024-10-31 07:30:38 +0100 |
commit | 24636cab40ec3e34b7d93e01aadf82a9940c8b93 (patch) | |
tree | e9b2a09e3c91c115ab67d5d8a1d3f3c36d3bf234 | |
parent | 8e6fd4d2780df1e0572bba9526ecce53e08b9661 (diff) | |
download | nextcloud-server-printOccHumanFriendly.tar.gz nextcloud-server-printOccHumanFriendly.zip |
feat(occ): add option to print values human-readableprintOccHumanFriendly
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
-rw-r--r-- | core/Command/User/Info.php | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index 55298f0164c..fde1a2a64c8 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -32,6 +33,11 @@ class Info extends Base { InputArgument::REQUIRED, 'user to show' )->addOption( + 'human', + null, + InputOption::VALUE_NONE, + 'Print storage values in human-readable format' + )->addOption( 'output', null, InputOption::VALUE_OPTIONAL, @@ -55,7 +61,7 @@ class Info extends Base { 'enabled' => $user->isEnabled(), 'groups' => $groups, 'quota' => $user->getQuota(), - 'storage' => $this->getStorageInfo($user), + 'storage' => $this->getStorageInfo($user, $input), 'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601 'user_directory' => $user->getHome(), 'backend' => $user->getBackendClassName() @@ -68,7 +74,7 @@ class Info extends Base { * @param IUser $user * @return array */ - protected function getStorageInfo(IUser $user): array { + protected function getStorageInfo(IUser $user, InputInterface $input): array { \OC_Util::tearDownFS(); \OC_Util::setupFS($user->getUID()); try { @@ -76,13 +82,23 @@ class Info extends Base { } catch (\OCP\Files\NotFoundException $e) { return []; } - return [ - 'free' => $storage['free'], - 'used' => $storage['used'], - 'total' => $storage['total'], - 'relative' => $storage['relative'], - 'quota' => $storage['quota'], - ]; + if ($input->getOption('human')) { + return [ + 'free' => \OC_Helper::humanFileSize($storage['free']), + 'used' => \OC_Helper::humanFileSize($storage['used']), + 'total' => \OC_Helper::humanFileSize($storage['total']), + 'relative' => $storage['relative'] . '%', + 'quota' => ($storage['quota'] >= 0) ? \OC_Helper::humanFileSize($storage['quota']) : $storage['quota'], + ]; + } else { + return [ + 'free' => $storage['free'], + 'used' => $storage['used'], + 'total' => $storage['total'], + 'relative' => $storage['relative'], + 'quota' => $storage['quota'], + ]; + } } /** |