Skip to content
Merged
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: 2 additions & 0 deletions packages/console/src/ConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function __construct(

/** @var class-string<\Tempest\Console\CompletesConsoleCommand>|null */
public readonly ?string $complete = null,

public readonly bool $allowDynamicArguments = false,
) {}

public function setHandler(MethodReflector $handler): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ final class ValidateNamedArgumentsMiddleware implements ConsoleMiddleware
{
public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next): ExitCode|int
{
if ($invocation->consoleCommand->allowDynamicArguments) {
return $next($invocation);
}

$allowedParameterNames = arr($invocation->consoleCommand->getArgumentDefinitions())
->flatMap(function (ConsoleArgumentDefinition $definition) {
return [$definition->name, ...$definition->aliases];
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ public function __construct(
private Container $container,
) {}

#[ConsoleCommand(name: 'install', description: 'Applies the specified installer', middleware: [ForceMiddleware::class])]
public function __invoke(?string $installer = null): void
#[ConsoleCommand(
name: 'install',
description: 'Applies the specified installer',
middleware: [ForceMiddleware::class],
allowDynamicArguments: true,
)]
public function __invoke(?string $installer = null, bool $_tailwind = false): void
{
$installer = $this->resolveInstaller($installer);

Expand Down
24 changes: 24 additions & 0 deletions tests/Fixtures/Commands/DynamicParamsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\Tempest\Fixtures\Commands;

use Tempest\Console\ConsoleCommand;
use Tempest\Console\HasConsole;
use Tempest\Console\Input\ConsoleArgumentBag;

final class DynamicParamsCommand
{
use HasConsole;

public function __construct(
private readonly ConsoleArgumentBag $consoleArgumentBag,
) {}

#[ConsoleCommand(allowDynamicArguments: true)]
public function __invoke(): void
{
$dynamic = $this->consoleArgumentBag->get('dynamic');

$this->console->info($dynamic ? 'yes' : 'no');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@ public function test_invalid_parameters_throw_exception(): void
->assertDoesNotContain('help')
->assertDoesNotContain('interaction');
}

public function test_command_with_dynamic_parameters(): void
{
$this->console
->call('dynamic:params --dynamic')
->assertContains('yes');

$this->console
->call('dynamic:params')
->assertContains('no');
}
}