Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: Add category/class type parameter to setupchecks cmd
Signed-off-by: Josh <[email protected]>
  • Loading branch information
joshtrichards committed Dec 28, 2024
commit f4d7620153a143502c5946fc61e96e56d7223a88
33 changes: 32 additions & 1 deletion core/Command/SetupChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call it limit?

Suggested change
$limit = $input->getArgument('type');
$type = $input->getArgument('type');


if (!is_string($limit)) {
$output->writeln('<error>Invalid type specified</error>');
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);
}
Comment on lines +55 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe introducing two distinct flags would make it more straightforward


if (empty($results)) {
$output->writeln('<error>Invalid type specified (or no results for that type)</error>');
return self::FAILURE;
}
}

switch ($input->getOption('output')) {
case self::OUTPUT_FORMAT_JSON:
case self::OUTPUT_FORMAT_JSON_PRETTY:
Expand Down