Skip to content

Commit 1628bd2

Browse files
committed
enh(occ): Add option to print values human-readable
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> fix: lint Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> fix: value fix: pass human as option Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1 parent 8e6fd4d commit 1628bd2

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

core/Command/User/Info.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ protected function configure() {
3131
'user',
3232
InputArgument::REQUIRED,
3333
'user to show'
34+
)->addOption(
35+
'human',
36+
null,
37+
InputOption::VALUE_NONE,
38+
'Print storage values in human-readable format'
3439
)->addOption(
3540
'output',
3641
null,
@@ -55,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5560
'enabled' => $user->isEnabled(),
5661
'groups' => $groups,
5762
'quota' => $user->getQuota(),
58-
'storage' => $this->getStorageInfo($user),
63+
'storage' => $this->getStorageInfo($user, $input),
5964
'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601
6065
'user_directory' => $user->getHome(),
6166
'backend' => $user->getBackendClassName()
@@ -68,21 +73,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6873
* @param IUser $user
6974
* @return array
7075
*/
71-
protected function getStorageInfo(IUser $user): array {
76+
protected function getStorageInfo(IUser $user, InputInterface $input): array {
7277
\OC_Util::tearDownFS();
7378
\OC_Util::setupFS($user->getUID());
7479
try {
7580
$storage = \OC_Helper::getStorageInfo('/');
7681
} catch (\OCP\Files\NotFoundException $e) {
7782
return [];
7883
}
79-
return [
80-
'free' => $storage['free'],
81-
'used' => $storage['used'],
82-
'total' => $storage['total'],
83-
'relative' => $storage['relative'],
84-
'quota' => $storage['quota'],
85-
];
84+
if ($input->getOption('human')) {
85+
return [
86+
'free' => \OC_Helper::humanFileSize($storage['free']),
87+
'used' => \OC_Helper::humanFileSize($storage['used']),
88+
'total' => \OC_Helper::humanFileSize($storage['total']),
89+
'relative' => $storage['relative'],
90+
'quota' => ($storage['quota'] >= 0) ? \OC_Helper::humanFileSize($storage['quota']) : $storage['quota'],
91+
];
92+
} else {
93+
return [
94+
'free' => $storage['free'],
95+
'used' => $storage['used'],
96+
'total' => $storage['total'],
97+
'relative' => $storage['relative'],
98+
'quota' => $storage['quota'],
99+
];
100+
}
86101
}
87102

88103
/**

0 commit comments

Comments
 (0)