Skip to content

Commit 97df391

Browse files
authored
Merge pull request #49978 from nextcloud/jtr-feat-setupchecks-limit-type
feat: Run setup checks by category or class
2 parents bf4b5ce + 69e3b94 commit 97df391

3 files changed

Lines changed: 81 additions & 3 deletions

File tree

core/Command/SetupChecks.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use OCP\RichObjectStrings\IRichTextFormatter;
1313
use OCP\SetupCheck\ISetupCheckManager;
14+
use Symfony\Component\Console\Input\InputArgument;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617

@@ -29,12 +30,44 @@ protected function configure(): void {
2930
$this
3031
->setName('setupchecks')
3132
->setDescription('Run setup checks and output the results')
33+
->addArgument(
34+
'category',
35+
InputArgument::OPTIONAL,
36+
'Category of setup checks to run ' . "\n" . '(e.g. "network" to run all the network-related checks)',
37+
''
38+
)
39+
->addArgument(
40+
'class',
41+
InputArgument::OPTIONAL,
42+
'Class of setup checks to run ' . "\n" . '(e.g. "OCA\\Settings\\SetupChecks\\InternetConnectivity" to run only the InternetConnectivity check)',
43+
''
44+
)
3245
;
3346
}
3447

3548
#[\Override]
3649
protected function execute(InputInterface $input, OutputInterface $output): int {
37-
$results = $this->setupCheckManager->runAll();
50+
$filterByCategory = $input->getArgument('category');
51+
$filterByClass = $input->getArgument('class');
52+
53+
if (!is_string($filterByCategory) || !is_string($filterByClass)) {
54+
$output->writeln('<error>Invalid type specified</error>');
55+
return self::FAILURE;
56+
}
57+
58+
if ($filterByCategory !== '' && $filterByClass !== '') {
59+
$output->writeln('<error>Please specify only one of category or class</error>');
60+
return self::FAILURE;
61+
}
62+
63+
if ($filterByCategory !== '') {
64+
$results = $this->setupCheckManager->runByCategory($filterByCategory);
65+
} elseif ($filterByClass !== '') {
66+
$results = $this->setupCheckManager->runByClass($filterByClass);
67+
} else {
68+
$results = $this->setupCheckManager->runAll();
69+
}
70+
3871
switch ($input->getOption('output')) {
3972
case self::OUTPUT_FORMAT_JSON:
4073
case self::OUTPUT_FORMAT_JSON_PRETTY:

lib/private/SetupCheck/SetupCheckManager.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,43 @@
1818

1919
class SetupCheckManager implements ISetupCheckManager {
2020
public function __construct(
21-
private Coordinator $coordinator,
22-
private LoggerInterface $logger,
21+
readonly private Coordinator $coordinator,
22+
readonly private LoggerInterface $logger,
2323
) {
2424
}
2525

26+
#[\Override]
27+
public function runByClass(string $filterByClass): array {
28+
if (str_starts_with($filterByClass, '\\')) {
29+
$filterByClass = substr($filterByClass, 1);
30+
}
31+
return $this->run(filterByClass: $filterByClass);
32+
}
33+
34+
#[\Override]
35+
public function runByCategory(string $filterByCategory): array {
36+
return $this->run(filterByCategory: $filterByCategory);
37+
}
38+
2639
#[\Override]
2740
public function runAll(): array {
41+
return $this->run();
42+
}
43+
44+
private function run(?string $filterByCategory = null, ?string $filterByClass = null): array {
2845
$results = [];
2946
$setupChecks = $this->coordinator->getRegistrationContext()->getSetupChecks();
3047
foreach ($setupChecks as $setupCheck) {
3148
/** @var ISetupCheck $setupCheckObject */
3249
$setupCheckObject = Server::get($setupCheck->getService());
50+
if ($filterByCategory !== null && $filterByCategory !== $setupCheckObject->getCategory()) {
51+
continue;
52+
}
53+
54+
if ($filterByClass !== null && $filterByClass !== get_class($setupCheckObject)) {
55+
continue;
56+
}
57+
3358
$this->logger->debug('Running check ' . get_class($setupCheckObject));
3459
try {
3560
$setupResult = $setupCheckObject->run();

lib/public/SetupCheck/ISetupCheckManager.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,28 @@
1414
*/
1515
interface ISetupCheckManager {
1616
/**
17+
* Run all setup checks and return the results.
18+
*
1719
* @since 28.0.0
1820
* @return array<string,array<string,SetupResult>> Result of each check, first level key is category, second level key is title
1921
*/
2022
public function runAll(): array;
23+
24+
/**
25+
* Run all tests from one specific category and return the results.
26+
*
27+
* @param string $filterByCategory - The id of the category to run.
28+
* @return array<string,array<string,SetupResult>> Result of each check, first level key is category, second level key is title
29+
* @since 35.0.0
30+
*/
31+
public function runByCategory(string $filterByCategory): array;
32+
33+
/**
34+
* Run all tests from one specific class and return the results.
35+
*
36+
* @param string $filterByClass - The class to run.
37+
* @return array<string,array<string,SetupResult>> Result of each check, first level key is category, second level key is title
38+
* @since 35.0.0
39+
*/
40+
public function runByClass(string $filterByClass): array;
2141
}

0 commit comments

Comments
 (0)