Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --context option ignored when another option presence (#593) #594

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 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,24 @@ 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());
}

// 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
Loading