Skip to content

Commit 3590a4e

Browse files
committed
feat(console): Expose output format
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent b0f79b1 commit 3590a4e

27 files changed

Lines changed: 178 additions & 69 deletions

apps/files/lib/Command/Copy.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ public function __construct(
3131
public function __invoke(
3232
IOutput $output,
3333
IQuestionHelper $questionHelper,
34-
#[Argument(description: 'Source file id or path')] string $source,
35-
#[Argument(description: 'Target path')] string $target,
34+
#[Argument(description: 'Source file id or path')]
35+
string $source,
36+
#[Argument(description: 'Target path')]
37+
string $target,
3638
#[Option(
3739
description: "Don't ask for confirmation and don't output any warnings",
3840
shortcut: 'f',
39-
)] bool $force = false,
41+
)]
42+
bool $force = false,
4043
#[Option(
4144
name: 'no-target-directory',
4245
description: 'When target path is folder, overwrite the folder instead of copying into the folder',
4346
shortcut: 'T',
44-
)] bool $noTargetDirectory = false,
47+
)]
48+
bool $noTargetDirectory = false,
4549
): ExitCode {
4650
$node = $this->fileUtils->getNode($source);
4751
$targetNode = $this->fileUtils->getNode($target);

apps/files/lib/Command/Delete.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ public function __construct(
3434
public function __invoke(
3535
IOutput $output,
3636
IQuestionHelper $questionHelper,
37-
#[Argument(description: 'File id or path')] string $file,
37+
#[Argument(description: 'File id or path')]
38+
string $file,
3839
#[Option(
3940
description: "Don't ask for configuration and don't output any warnings",
4041
shortcut: 'f',
41-
)] bool $force = false,
42-
#[Option(name: 'skip-trash', description: 'Bypass the trashbin when deleting the file or folder')] bool $skipTrash = false,
42+
)]
43+
bool $force = false,
44+
#[Option(name: 'skip-trash', description: 'Bypass the trashbin when deleting the file or folder')]
45+
bool $skipTrash = false,
4346
): ExitCode {
4447
$inputIsId = is_numeric($file);
4548
$node = $this->fileUtils->getNode($file);

apps/files/lib/Command/DeleteOrphanedFiles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
help: 'Deletes orphaned filecache and mount entries (those without an existing storage).',
2727
)]
2828
class DeleteOrphanedFiles {
29-
public const CHUNK_SIZE = 200;
29+
public const int CHUNK_SIZE = 200;
3030

3131
public function __construct(
3232
protected readonly IDBConnection $connection,

apps/files/lib/Command/Get.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public function __construct(
2727

2828
public function __invoke(
2929
IOutput $output,
30-
#[Argument(description: 'Source file id or Nextcloud path')] string $file,
31-
#[Argument(name: 'output', description: 'Target local file to output to, defaults to STDOUT')] ?string $outputFile = null,
30+
#[Argument(description: 'Source file id or Nextcloud path')]
31+
string $file,
32+
#[Argument(name: 'output', description: 'Target local file to output to, defaults to STDOUT')]
33+
?string $outputFile = null,
3234
): ExitCode {
3335
$node = $this->fileUtils->getNode($file);
3436

apps/files/lib/Command/Mkdir.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public function __construct(
3030

3131
public function __invoke(
3232
IOutput $output,
33-
#[Argument(description: 'Target Nextcloud path for the new folder')] string $path,
33+
#[Argument(description: 'Target Nextcloud path for the new folder')]
34+
string $path,
3435
): ExitCode {
3536
$node = $this->fileUtils->getNode($path);
3637

apps/files/lib/Command/Mount/ListMounts.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\Console\ExitCode;
1515
use OCP\Console\IInput;
1616
use OCP\Console\IOutput;
17+
use OCP\Console\OutputFormat;
1718
use OCP\Files\Config\ICachedMountInfo;
1819
use OCP\Files\Config\IMountProviderCollection;
1920
use OCP\Files\Config\IUserMountCache;
@@ -23,6 +24,7 @@
2324
#[AsCommand(
2425
name: 'files:mount:list',
2526
description: 'List of mounts for a user',
27+
supportsOutputFormat: true,
2628
)]
2729
class ListMounts {
2830
public function __construct(
@@ -35,8 +37,11 @@ public function __construct(
3537
public function __invoke(
3638
IInput $input,
3739
IOutput $output,
38-
#[Argument(description: 'User to list mounts for')] string $user,
39-
#[Option(name: 'cached-only', description: 'Only return cached mounts, prevents filesystem setup')] bool $cachedOnly = false,
40+
OutputFormat $outputFormat,
41+
#[Argument(description: 'User to list mounts for')]
42+
string $user,
43+
#[Option(name: 'cached-only', description: 'Only return cached mounts, prevents filesystem setup')]
44+
bool $cachedOnly = false,
4045
): ExitCode {
4146
$userId = $user;
4247
$user = $this->userManager->get($userId);
@@ -60,9 +65,7 @@ public function __invoke(
6065
/** @var array<string, ICachedMountInfo> $cachedByMountpoint */
6166
$cachedByMountPoint = array_combine(array_map(fn (ICachedMountInfo $mount) => $mount->getMountPoint(), $cachedMounts), $cachedMounts);
6267

63-
$format = $input->getOption('output');
64-
65-
if ($format === 'plain') {
68+
if ($outputFormat === OutputFormat::Plain) {
6669
foreach ($mounts as $mount) {
6770
$output->writeln('<info>' . $mount->getMountPoint() . '</info>: ' . $mount->getStorageId());
6871
if (isset($cachedByMountPoint[$mount->getMountPoint()])) {

apps/files/lib/Command/Mount/Refresh.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public function __construct(
3030

3131
public function __invoke(
3232
IOutput $output,
33-
#[Argument(description: 'User to refresh mounts for')] string $user,
33+
#[Argument(description: 'User to refresh mounts for')]
34+
string $user,
3435
): ExitCode {
3536
$userId = $user;
3637
$user = $this->userManager->get($userId);

apps/files/lib/Command/Move.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ public function __construct(
3232
public function __invoke(
3333
IOutput $output,
3434
IQuestionHelper $questionHelper,
35-
#[Argument(description: 'Source file id or path')] string $source,
36-
#[Argument(description: 'Target path')] string $target,
35+
#[Argument(description: 'Source file id or path')]
36+
string $source,
37+
#[Argument(description: 'Target path')]
38+
string $target,
3739
#[Option(
3840
description: "Don't ask for configuration and don't output any warnings",
3941
shortcut: 'f',
40-
)] bool $force = false,
42+
)]
43+
bool $force = false,
4144
): ExitCode {
4245
$node = $this->fileUtils->getNode($source);
4346
$targetNode = $this->fileUtils->getNode($target);

apps/files/lib/Command/Object/Delete.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public function __construct(
2929
public function __invoke(
3030
IOutput $output,
3131
IQuestionHelper $questionHelper,
32-
#[Argument(description: 'Object to delete')] string $object,
33-
#[Option(description: "Bucket to delete the object from, only required in cases where it can't be determined from the config", shortcut: 'b')] ?string $bucket = null,
32+
#[Argument(description: 'Object to delete')]
33+
string $object,
34+
#[Option(description: "Bucket to delete the object from, only required in cases where it can't be determined from the config", shortcut: 'b')]
35+
?string $bucket = null,
3436
): ExitCode|int {
3537
$objectStore = $this->objectUtils->getObjectStore($bucket, $output);
3638
if (!$objectStore) {

apps/files/lib/Command/Object/Get.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ public function __construct(
2626

2727
public function __invoke(
2828
IOutput $output,
29-
#[Argument(description: 'Object to get')] string $object,
30-
#[Argument(name: 'output', description: 'Target local file to output to, use - for STDOUT')] string $outputFile,
31-
#[Option(description: "Bucket to get the object from, only required in cases where it can't be determined from the config", shortcut: 'b')] ?string $bucket = null,
29+
#[Argument(description: 'Object to get')]
30+
string $object,
31+
#[Argument(name: 'output', description: 'Target local file to output to, use - for STDOUT')]
32+
string $outputFile,
33+
#[Option(description: "Bucket to get the object from, only required in cases where it can't be determined from the config", shortcut: 'b')]
34+
?string $bucket = null,
3235
): ExitCode {
3336
$objectStore = $this->objectUtils->getObjectStore($bucket, $output);
3437
if (!$objectStore) {

0 commit comments

Comments
 (0)