From e813ef74b4e6db06515714d9af663b42bbdd21aa Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Mon, 18 Nov 2024 11:58:44 -0600 Subject: [PATCH 1/3] Allow for custom default command execution without arguments --- src/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.php b/src/Application.php index 4e15610..3b41793 100644 --- a/src/Application.php +++ b/src/Application.php @@ -308,7 +308,7 @@ public function onException(callable $fn): self */ public function handle(array $argv): mixed { - if (count($argv) < 2) { + if ($this->default === '__default__' && count($argv) < 2) { return $this->showHelp(); } From 526dae66f72ffd63e18b8d9ac735b7cf615aed4d Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Tue, 19 Nov 2024 10:01:14 -0600 Subject: [PATCH 2/3] Add a test for default command execution --- tests/ApplicationTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index e5f7dee..7b10977 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -312,13 +312,21 @@ public function testDefaultCommand() $app = $this->newApp('test'); // Add some sample commands to the application - $app->command('command1'); + $app->command('command1')->action(function () { + echo 'This should be the default command'; + }); $app->command('command2'); // Test setting a valid default command $app->defaultCommand('command1'); $this->assertEquals('command1', $app->getDefaultCommand()); + // Test executing a default command + ob_start(); + $app->handle(['test']); + $buffer = ob_get_clean(); + $this->assertSame('This should be the default command', $buffer); + // Test setting an invalid default command $this->expectException(InvalidArgumentException::class); $app->defaultCommand('invalid_command'); From ccf09f46fff506f8ea1525d8916460652277ca04 Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Tue, 19 Nov 2024 10:02:27 -0600 Subject: [PATCH 3/3] Fix testDefaultCommand command1 action indentation --- tests/ApplicationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index 7b10977..b6fce4f 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -313,7 +313,7 @@ public function testDefaultCommand() // Add some sample commands to the application $app->command('command1')->action(function () { - echo 'This should be the default command'; + echo 'This should be the default command'; }); $app->command('command2');