diff --git a/README.md b/README.md index a45e534..4708425 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # clue/reactphp-shell -[![CI status](https://github.com/clue/reactphp-shell/workflows/CI/badge.svg)](https://github.com/clue/reactphp-shell/actions) +[![CI status](https://github.com/clue/reactphp-shell/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/reactphp-shell/actions) [![installs on Packagist](https://img.shields.io/packagist/dt/clue/shell-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/shell-react) Run async commands within any interactive shell command, built on top of [ReactPHP](https://reactphp.org/). @@ -13,22 +13,30 @@ Once [installed](#install), you can use the following code to run an interactive bash shell and issue some commands within: ```php +createDeferredShell('bash'); $shell->execute('echo -n $USER')->then(function ($result) { var_dump('current user', $result); +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->execute('env | sort | head -n10')->then(function ($env) { var_dump('env', $env); +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->end(); ``` -See also the [examples](examples): +See also the [examples](examples/): * [Run shell commands within a bash shell](examples/bash.php) * [Run PHP code within an interactive PHP shell](examples/php.php) @@ -36,34 +44,34 @@ See also the [examples](examples): ## Install -The recommended way to install this library is [through Composer](https://getcomposer.org). +The recommended way to install this library is [through Composer](https://getcomposer.org/). [New to Composer?](https://getcomposer.org/doc/00-intro.md) This will install the latest supported version: ```bash -$ composer require clue/shell-react:^0.2 +composer require clue/shell-react:^0.2 ``` See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades. This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+. -It's *highly recommended to use PHP 7+* for this project. +It's *highly recommended to use the latest supported PHP version* for this project. ## Tests To run the test suite, you first need to clone this repo and then install all -dependencies [through Composer](https://getcomposer.org): +dependencies [through Composer](https://getcomposer.org/): ```bash -$ composer install +composer install ``` To run the test suite, go to the project root and run: ```bash -$ php vendor/bin/phpunit +vendor/bin/phpunit ``` ## License diff --git a/examples/bash.php b/examples/bash.php index e75cc80..bf7c190 100644 --- a/examples/bash.php +++ b/examples/bash.php @@ -1,19 +1,21 @@ createDeferredShell('bash 2>&1'); $shell->execute('echo -n $USER')->then(function ($result) { var_dump('current user', $result); +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->execute('env | sort | head -n10')->then(function ($env) { var_dump('env', $env); +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->end(); diff --git a/examples/docker.php b/examples/docker.php index 8f706e4..ac1a5c1 100644 --- a/examples/docker.php +++ b/examples/docker.php @@ -1,19 +1,21 @@ createDeferredShell('docker run -i --rm debian bash'); $shell->execute('id')->then(function ($result) { var_dump('current user', $result); +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->execute('env')->then(function ($env) { var_dump('env', $env); +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->end(); diff --git a/examples/php.php b/examples/php.php index 5554a48..1f71dc3 100644 --- a/examples/php.php +++ b/examples/php.php @@ -1,10 +1,8 @@ createDeferredShell('php -a'); $shell->setBounding("echo '{{ bounding }}';"); @@ -19,6 +17,8 @@ CODE )->then(function ($output) { echo 'Program output: ' . PHP_EOL . $output . PHP_EOL; +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->end();