summaryrefslogtreecommitdiffstats
path: root/core/Command
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-01-04 16:27:18 +0100
committerJohn Molakvoæ <skjnldsv@protonmail.com>2024-01-15 15:11:56 +0100
commit25c91e6eea73833bbd44d06e3a36725a64d557c4 (patch)
tree8905227a37a1a28de499e2b492cbeafbbcdb1eb2 /core/Command
parent4eaf7e7bbd6a19312a8e962631b66ace53301cff (diff)
downloadnextcloud-server-25c91e6eea73833bbd44d06e3a36725a64d557c4.tar.gz
nextcloud-server-25c91e6eea73833bbd44d06e3a36725a64d557c4.zip
Add RichObject support for SetupChecks descriptions
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'core/Command')
-rw-r--r--core/Command/SetupChecks.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php
index bd76a9d1e65..0940a139617 100644
--- a/core/Command/SetupChecks.php
+++ b/core/Command/SetupChecks.php
@@ -45,6 +45,30 @@ class SetupChecks extends Base {
;
}
+ /**
+ * @throws \InvalidArgumentException if a parameter has no name or no type
+ */
+ private function richToParsed(string $message, array $parameters): string {
+ $placeholders = [];
+ $replacements = [];
+ foreach ($parameters as $placeholder => $parameter) {
+ $placeholders[] = '{' . $placeholder . '}';
+ foreach (['name','type'] as $requiredField) {
+ if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) {
+ throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing");
+ }
+ }
+ if ($parameter['type'] === 'user') {
+ $replacements[] = '@' . $parameter['name'];
+ } elseif ($parameter['type'] === 'file') {
+ $replacements[] = $parameter['path'] ?? $parameter['name'];
+ } else {
+ $replacements[] = $parameter['name'];
+ }
+ }
+ return str_replace($placeholders, $replacements, $message);
+ }
+
protected function execute(InputInterface $input, OutputInterface $output): int {
$results = $this->setupCheckManager->runAll();
switch ($input->getOption('output')) {
@@ -70,6 +94,10 @@ class SetupChecks extends Base {
};
$verbosity = ($check->getSeverity() === 'error' ? OutputInterface::VERBOSITY_QUIET : OutputInterface::VERBOSITY_NORMAL);
$description = $check->getDescription();
+ $descriptionParameters = $check->getDescriptionParameters();
+ if ($descriptionParameters !== null) {
+ $description = $this->richToParsed($description, $descriptionParameters);
+ }
$output->writeln(
"\t\t".
($styleTag !== null ? "<{$styleTag}>" : '').