Skip to content

Commit

Permalink
fix: --context option ignored when another option presence (jolicode#593
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TheoD02 committed Dec 19, 2024
1 parent 902c05d commit 826ee4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/context.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function contextFromPath(): Context
}

#[AsTask(description: 'Displays information about the context', name: 'context')]
function contextInfo(): void
function contextInfo(bool $test = false): void
{
$context = context();
io()->writeln('context name: ' . variable('name', 'N/A'));
Expand Down
21 changes: 21 additions & 0 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Castor\Event\BeforeBootEvent;
use Castor\Event\FunctionsResolvedEvent;
use Castor\Exception\CouldNotFindEntrypointException;
use Castor\Factory\TaskCommandFactory;
use Castor\Function\FunctionLoader;
use Castor\Function\FunctionResolver;
use Castor\Helper\PlatformHelper;
Expand Down Expand Up @@ -46,6 +47,7 @@ public function __construct(
private readonly FunctionResolver $functionResolver,
private readonly FunctionLoader $functionLoader,
private readonly ContextRegistry $contextRegistry,
private readonly TaskCommandFactory $taskCommandFactory,
) {
}

Expand Down Expand Up @@ -123,6 +125,25 @@ private function load(

$this->functionLoader->loadListeners($descriptorsCollection->listenerDescriptors);

$taskCommand = null;
foreach ($descriptorsCollection->taskDescriptors as $taskDescriptor) {
$namespace = $taskDescriptor->taskAttribute->namespace;
$taskName = $taskDescriptor->taskAttribute->name;
$fullTaskName = $namespace ? $namespace . ':' . $taskName : $taskName;
if ($fullTaskName === $input->getFirstArgument()) {
$taskCommand = $this->taskCommandFactory->createTask($taskDescriptor);

break;
}
}

$taskDefinition = $taskCommand?->getDefinition();

if (null !== $taskDefinition) {
$this->application->getDefinition()->addOptions($taskDefinition->getOptions());
$this->application->getDefinition()->addArguments($taskDefinition->getArguments());
}

// Must load contexts before tasks, because tasks can be disabled
// depending on the context. And it must be before executing
// listeners too, to get the context there.
Expand Down

0 comments on commit 826ee4e

Please sign in to comment.