Skip to content

Commit

Permalink
CLI output cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Nov 19, 2024
1 parent 30b4ce2 commit 400c740
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/console/controllers/ResaveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use craft\events\MultiElementActionEvent;
use craft\helpers\Console;
use craft\helpers\ElementHelper;
use craft\helpers\Inflector;
use craft\helpers\Queue;
use craft\helpers\StringHelper;
use craft\models\CategoryGroup;
Expand Down Expand Up @@ -383,39 +384,31 @@ public function actionAll(): int
}
}

$proceed = true;
// ask for confirmation
if ($this->interactive && !empty($actionsToSkip)) {
$this->output('Following commands, don’t support all the provided options:', Console::FG_YELLOW);
$this->output('The following commands don’t support the provided options, and will be skipped:', Console::FG_YELLOW);
foreach ($actionsToSkip as $id) {
$invalidParams = array_map(
fn($param) => '--' . StringHelper::toKebabCase($param),
fn($param) => sprintf('`--%s`', StringHelper::toKebabCase($param)),
$this->getUnsupportedOptions($id, $params)
);
$count = count($invalidParams);
$invalidParams = implode(', ', $invalidParams);
Console::indent();
$this->output(
$this->markdownToAnsi(
"- `resave/$id` action doesn’t support `$invalidParams` option" . ($count > 1 ? 's.' : '.')
)
);
Console::outdent();
$this->output(' ' . $this->markdownToAnsi(sprintf(
'- `resave/%s` doesn’t support %s',
$id,
Inflector::sentence($invalidParams)
)));
}
Console::outdent();
if (!$this->confirm('Continue?', true)) {
return ExitCode::OK;
}
$this->output();
$proceed = $this->confirm('Do you want to run all other actions?');
}

if (!$proceed) {
return ExitCode::OK;
}

// run the actions which support all the params
foreach ($actions as $id) {
try {
$this->output();
$this->do("Running `resave/$id`", function() use ($id, $params) {
$this->output();
Console::indent();
try {
$this->runAction($id, $params);
Expand Down Expand Up @@ -840,7 +833,6 @@ private function _resaveElements(ElementQueryInterface $query): int

$label = isset($this->propagateTo) ? 'propagating' : 'resaving';
$this->output("Done $label $elementsText.", Console::FG_YELLOW);
$this->output();
return $fail ? ExitCode::UNSPECIFIED_ERROR : ExitCode::OK;
}

Expand Down

0 comments on commit 400c740

Please sign in to comment.