diff --git a/docs/debugging.md b/docs/debugging.md index 8792cb6e9..0ddd91628 100644 --- a/docs/debugging.md +++ b/docs/debugging.md @@ -42,6 +42,10 @@ examples\Layer1\SomeClass examples\Layer1\SomeClass2 ``` +This command exist with the return code 2 when it ran successfully, but there +were some tokens in the output. You can use this information in your CI +pipelines. + ## `debug:dependencies` With the `debug:dependencies`-command you can see all dependencies of your layer. You can optionally specify a target layer to get only dependencies from one layer to the other: diff --git a/src/Supportive/Console/Command/DebugUnassignedCommand.php b/src/Supportive/Console/Command/DebugUnassignedCommand.php index ded59cf5d..42ad33188 100644 --- a/src/Supportive/Console/Command/DebugUnassignedCommand.php +++ b/src/Supportive/Console/Command/DebugUnassignedCommand.php @@ -15,6 +15,7 @@ class DebugUnassignedCommand extends Command { public static $defaultName = 'debug:unassigned'; public static $defaultDescription = 'Lists tokens that are not assigned to any layer'; + public const EXIT_WITH_UNASSIGNED_TOKENS = 2; public function __construct(private readonly DebugUnassignedRunner $runner) { @@ -27,13 +28,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $symfonyOutput = new SymfonyOutput($output, $outputStyle); try { - $this->runner->run($symfonyOutput); + $result = $this->runner->run($symfonyOutput); + return $result ? self::EXIT_WITH_UNASSIGNED_TOKENS : self::SUCCESS; } catch (CommandRunException $exception) { $outputStyle->error($exception->getMessage()); return self::FAILURE; } - return self::SUCCESS; } } diff --git a/src/Supportive/Console/Command/DebugUnassignedRunner.php b/src/Supportive/Console/Command/DebugUnassignedRunner.php index 963d05895..cf3f71a53 100644 --- a/src/Supportive/Console/Command/DebugUnassignedRunner.php +++ b/src/Supportive/Console/Command/DebugUnassignedRunner.php @@ -17,8 +17,10 @@ public function __construct(private readonly UnassignedTokenAnalyser $analyser) /** * @throws CommandRunException + * + * @return bool are there any unassigned tokens? */ - public function run(OutputInterface $output): void + public function run(OutputInterface $output): bool { try { $unassignedTokens = $this->analyser->findUnassignedTokens(); @@ -29,9 +31,11 @@ public function run(OutputInterface $output): void if ([] === $unassignedTokens) { $output->writeLineFormatted('There are no unassigned tokens.'); - return; + return false; } $output->writeLineFormatted($unassignedTokens); + + return true; } }