Skip to content

Commit cb9e2b3

Browse files
committed
docs: application handler
1 parent 058b9a3 commit cb9e2b3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ Framework agnostic Command Line Interface utilities and helpers for PHP. Build C
88
[![Codecov branch](https://img.shields.io/codecov/c/github/adhocore/php-cli/main.svg?style=flat-square)](https://codecov.io/gh/adhocore/php-cli)
99
[![StyleCI](https://styleci.io/repos/139012552/shield)](https://styleci.io/repos/139012552)
1010
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
11-
[![Donate 15](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square&label=donate+15)](https://www.paypal.me/ji10/15usd)
12-
[![Donate 25](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square&label=donate+25)](https://www.paypal.me/ji10/25usd)
13-
[![Donate 50](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square&label=donate+50)](https://www.paypal.me/ji10/50usd)
1411
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Framework+agnostic+Command+Line+Interface+utilities+and+helpers+for+PHP&url=https://github.com/adhocore/php-cli&hashtags=php,cli,cliapp,console)
12+
[![Support](https://img.shields.io/static/v1?label=Support&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/adhocore)
13+
<!-- [![Donate 15](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square&label=donate+15)](https://www.paypal.me/ji10/15usd)
14+
[![Donate 25](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square&label=donate+25)](https://www.paypal.me/ji10/25usd)
15+
[![Donate 50](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square&label=donate+50)](https://www.paypal.me/ji10/50usd) -->
1516

1617

1718
- Command line application made easy
@@ -252,6 +253,25 @@ $app->add((new ConfigListCommand)->inGroup('Config'));
252253
...
253254
```
254255

256+
#### Exception handler
257+
258+
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.
259+
260+
```php
261+
$app = new Ahc\Cli\Application('App', 'v0.0.1');
262+
$app->add(...);
263+
$app->onException(function (Throwable $e, int $exitCode) {
264+
// send to sentry
265+
// write to logs
266+
267+
// optionally, exit with exit code:
268+
exit($exitCode);
269+
270+
// or optionally rethrow, a rethrown exception is propagated to top layer caller.
271+
throw $e;
272+
})->handle($argv);
273+
```
274+
255275
#### App help
256276

257277
It can be triggered manually with `$app->showHelp()` or automatic when `-h` or `--help` option is passed to `$app->parse()`.

0 commit comments

Comments
 (0)