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(); } diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index e5f7dee..b6fce4f 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');