diff --git a/packages/console/src/ConsoleCommand.php b/packages/console/src/ConsoleCommand.php index c86eecb22..b7c057f2e 100644 --- a/packages/console/src/ConsoleCommand.php +++ b/packages/console/src/ConsoleCommand.php @@ -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 diff --git a/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php b/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php index aeabbfe2c..f1fdf0370 100644 --- a/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php +++ b/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php @@ -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]; diff --git a/packages/core/src/Commands/InstallCommand.php b/packages/core/src/Commands/InstallCommand.php index b83e32dce..0cc56ac7a 100644 --- a/packages/core/src/Commands/InstallCommand.php +++ b/packages/core/src/Commands/InstallCommand.php @@ -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); diff --git a/tests/Fixtures/Commands/DynamicParamsCommand.php b/tests/Fixtures/Commands/DynamicParamsCommand.php new file mode 100644 index 000000000..632f91f7b --- /dev/null +++ b/tests/Fixtures/Commands/DynamicParamsCommand.php @@ -0,0 +1,24 @@ +consoleArgumentBag->get('dynamic'); + + $this->console->info($dynamic ? 'yes' : 'no'); + } +} diff --git a/tests/Integration/Console/Middleware/ValidateNamedArgumentsMiddlewareTest.php b/tests/Integration/Console/Middleware/ValidateNamedArgumentsMiddlewareTest.php index 664060cef..99cdc5fe7 100644 --- a/tests/Integration/Console/Middleware/ValidateNamedArgumentsMiddlewareTest.php +++ b/tests/Integration/Console/Middleware/ValidateNamedArgumentsMiddlewareTest.php @@ -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'); + } }