Skip to content

Commit

Permalink
feat(debug:unassigned) now returns exit status 2 when the command ran…
Browse files Browse the repository at this point in the history
… successfully, but there were some unassigned tokens. (#1398)

* debug:unassigned now returns exit status 2 when the command ran successfully, but there were some unassigned tokens. This is useful for CI.
  • Loading branch information
patrickkusebauch authored Mar 12, 2024
1 parent f56ea07 commit c144e1b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/Supportive/Console/Command/DebugUnassignedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
}
8 changes: 6 additions & 2 deletions src/Supportive/Console/Command/DebugUnassignedRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ final class DebugUnassignedRunner
public function __construct(private readonly UnassignedTokenAnalyser $analyser) {}

/**
* @return bool are there any unassigned tokens?
*
* @throws CommandRunException
*/
public function run(OutputInterface $output): void
public function run(OutputInterface $output): bool
{
try {
$unassignedTokens = $this->analyser->findUnassignedTokens();
Expand All @@ -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;
}
}

0 comments on commit c144e1b

Please sign in to comment.