Skip to content

Commit

Permalink
Allow all --everything to run through using force mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 27, 2024
1 parent 9ea800f commit 4a4a1ff
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Command/AllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Datasource\ConnectionManager;
use Throwable;

/**
* Command for `bake all`
Expand Down Expand Up @@ -49,7 +50,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
$parser = $this->_setCommonOptions($parser);

$parser = $parser->setDescription(
'Generate the model, controller, template, tests and fixture for a table.'
'Generate the model, controller, template, tests and fixture for a table.',
)->addArgument('name', [
'help' => 'Name of the table to generate code for.',
])->addOption('everything', [
Expand Down Expand Up @@ -83,7 +84,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
/** @var \Cake\Database\Connection $connection */
$connection = ConnectionManager::get($this->connection);
$scanner = new TableScanner($connection);
if (empty($name) && !$args->getOption('everything')) {
if (!$name && !$args->getOption('everything')) {
$io->out('Choose a table to generate from the following:');
foreach ($scanner->listUnskipped() as $table) {
$io->out('- ' . $this->_camelize($table));
Expand All @@ -110,15 +111,31 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
unset($options['prefix']);
}

$errors = 0;
foreach ($tables as $table) {
$parser = $command->getOptionParser();
$subArgs = new Arguments([$table], $options, $parser->argumentNames());
$command->execute($subArgs, $io);

try {
$command->execute($subArgs, $io);
} catch (Throwable $e) {
if (!$args->getOption('everything') || !$args->getOption('force')) {
throw $e;

Check warning on line 123 in src/Command/AllCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/AllCommand.php#L121-L123

Added lines #L121 - L123 were not covered by tests
}

$message = sprintf('Error generating %s for %s: %s', $commandName, $table, $e->getMessage());
$io->err('<error>' . $message . '</error>');
$errors++;

Check warning on line 128 in src/Command/AllCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/AllCommand.php#L126-L128

Added lines #L126 - L128 were not covered by tests
}
}
}

$io->out('<success>Bake All complete.</success>', 1, ConsoleIo::NORMAL);
if ($errors) {

Check failure on line 133 in src/Command/AllCommand.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Variable $errors might not be defined.
$io->out(sprintf('<warning>Bake All completed, but with %s errors.</warning>', $errors), 1, ConsoleIo::NORMAL);

Check warning on line 134 in src/Command/AllCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/AllCommand.php#L134

Added line #L134 was not covered by tests
} else {
$io->out('<success>Bake All complete.</success>', 1, ConsoleIo::NORMAL);
}

return static::CODE_SUCCESS;
return $errors ? static::CODE_ERROR : static::CODE_SUCCESS;
}
}

0 comments on commit 4a4a1ff

Please sign in to comment.