Skip to content

Commit 96c51fe

Browse files
committed
Add documentation about default command functionality
1 parent 21d49f7 commit 96c51fe

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,21 @@ $app->add((new ConfigListCommand)->inGroup('Config'));
274274
...
275275
```
276276

277+
#### Default command
278+
279+
By default, running your CLI app without any arguments will show the help screen. However you can set the default action to run one of your commands either by setting the third parameter of the `add` function to `true` or by using the `defaultCommand` function.
280+
281+
```php
282+
$app->add(new InitCommand, 'i', true);
283+
284+
# Alternatively
285+
$app->command('init', 'Init something', 'i');
286+
$app->defaultCommand('init');
287+
288+
# Retrieve the name of the default command
289+
$default_command = $app->getDefaultCommand();
290+
```
291+
277292
#### Exception handler
278293

279294
Set a custom exception handler as callback. The callback receives exception & exit code. The callback may rethrow exception or may exit the program or just log exception and do nothing else.

0 commit comments

Comments
 (0)