Skip to content

Commit

Permalink
enh(occ): Add option to print values human-readable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
solracsf committed Oct 30, 2024
1 parent 8e6fd4d commit 1628bd2
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions core/Command/User/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ protected function configure() {
'user',
InputArgument::REQUIRED,
'user to show'
)->addOption(
'human',
null,
InputOption::VALUE_NONE,
'Print storage values in human-readable format'
)->addOption(
'output',
null,
Expand All @@ -55,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'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()
Expand All @@ -68,21 +73,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int
* @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 {
$storage = \OC_Helper::getStorageInfo('/');
} 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'],
];
}
}

/**
Expand Down

0 comments on commit 1628bd2

Please sign in to comment.