@@ -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