diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php
index 60517e224b320..1d40e3ab4632a 100644
--- a/core/Command/SetupChecks.php
+++ b/core/Command/SetupChecks.php
@@ -11,6 +11,7 @@
use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\SetupCheck\ISetupCheckManager;
+use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -28,11 +29,41 @@ protected function configure(): void {
$this
->setName('setupchecks')
->setDescription('Run setup checks and output the results')
+ ->addArgument(
+ 'type',
+ InputArgument::OPTIONAL,
+ 'Category (or class) of setup checks to run ' . "\n" . '(e.g. "network" to run all the network-related checks or "OCA\\Settings\\SetupChecks\\InternetConnectivity" to run only the InternetConnectivity check)',
+ 'all'
+ )
;
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $results = $this->setupCheckManager->runAll();
+ $limit = $input->getArgument('type');
+
+ if (!is_string($limit)) {
+ $output->writeln('Invalid type specified');
+ return self::FAILURE;
+ }
+
+ switch ($limit) {
+ case 'all': // run all checks (the default)
+ $results = $this->setupCheckManager->runAll();
+ break;
+
+ default: // limit checks to a specific category or class
+ if (substr_count($limit, '\\') > 1) {
+ $results = $this->setupCheckManager->runClass($limit);
+ } else {
+ $results = $this->setupCheckManager->runCategory($limit);
+ }
+
+ if (empty($results)) {
+ $output->writeln('Invalid type specified (or no results for that type)');
+ return self::FAILURE;
+ }
+ }
+
switch ($input->getOption('output')) {
case self::OUTPUT_FORMAT_JSON:
case self::OUTPUT_FORMAT_JSON_PRETTY:
diff --git a/lib/private/SetupCheck/SetupCheckManager.php b/lib/private/SetupCheck/SetupCheckManager.php
index 721885848e291..8bfa9ea4c3597 100644
--- a/lib/private/SetupCheck/SetupCheckManager.php
+++ b/lib/private/SetupCheck/SetupCheckManager.php
@@ -22,13 +22,31 @@ public function __construct(
private LoggerInterface $logger,
) {
}
-
+
+ public function runClass(string $limitClass): array {
+ if (str_starts_with($limitClass, '\\')) {
+ $limitClass = substr($limitClass, 1);
+ }
+ return $this->run($limitClass);
+ }
+
+ public function runCategory(string $limitCategory): array {
+ return $this->run($limitCategory);
+ }
+
public function runAll(): array {
+ return $this->run();
+ }
+
+ private function run(?string $limit = null): array {
$results = [];
$setupChecks = $this->coordinator->getRegistrationContext()->getSetupChecks();
foreach ($setupChecks as $setupCheck) {
/** @var ISetupCheck $setupCheckObject */
$setupCheckObject = Server::get($setupCheck->getService());
+ if (isset($limit) && $limit !== $setupCheckObject->getCategory() && $limit !== get_class($setupCheckObject)) {
+ continue;
+ }
$this->logger->debug('Running check ' . get_class($setupCheckObject));
try {
$setupResult = $setupCheckObject->run();
diff --git a/lib/public/SetupCheck/ISetupCheckManager.php b/lib/public/SetupCheck/ISetupCheckManager.php
index 6245be3933a6f..299fc5cea534d 100644
--- a/lib/public/SetupCheck/ISetupCheckManager.php
+++ b/lib/public/SetupCheck/ISetupCheckManager.php
@@ -18,4 +18,15 @@ interface ISetupCheckManager {
* @return array> Result of each check, first level key is category, second level key is title
*/
public function runAll(): array;
+ /**
+ * @since 31.0.0
+ * @return array> Result of each check, first level key is category, second level key is title
+ */
+ public function runClass(string $limitClass): array;
+ /**
+ * @since 31.0.0
+ * @return array> Result of each check, first level key is category, second level key is title
+ */
+ public function runCategory(string $limitCategory): array;
+
}